Base solution for your next web application

Activities of "naeazach"

Question

First of all, I'd like to thank you for an excellent starter project. I had been developing and using something similar the last few years but no where near this built out. You literally saved me a few months of frustration on my current project.

Please excuse my ignorance as I'm used to using DataFirst Entity Objects so extending/adding a table is obviously much simpler with an EDMX in the project. What I'd like to do is one of the following:

Extend the User object to add profile info (company, addr info, etc). Add a UserProfile table with a parent relationship to the user table.

Any suggestion on where to achieve this in the project?

After adding a few profile fields on my tenant table now I cant login to the system. This is the error in the log:

It's only logging the normal system exception unfortunately so i really have no way to see where the validation is failing. a) Any thoughts on this? Any idea what else happens on the login that would cause an update or insert? My login logs are empty as well so I feel like that is where its failing. b) Is extending the tenant object a bad idea?

ERROR 2015-07-14 21:25:24,024 [11 ] .Mvc.Controllers.AbpHandleErrorAttribute - System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. at System.Data.Entity.Internal.InternalContext.SaveChangesAsync(CancellationToken cancellationToken) at System.Data.Entity.Internal.LazyInternalContext.SaveChangesAsync(CancellationToken cancellationToken) at System.Data.Entity.DbContext.SaveChangesAsync(CancellationToken cancellationToken) at Abp.EntityFramework.AbpDbContext.SaveChangesAsync(CancellationToken cancellationToken) at System.Data.Entity.DbContext.SaveChangesAsync() at Abp.EntityFramework.Uow.EfUnitOfWork.<SaveChangesInDbContextAsync>d__a.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Abp.EntityFramework.Uow.EfUnitOfWork.<SaveChangesAsync>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Abp.Authorization.Users.AbpUserManager3.<LoginAsync>d__37.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at NAEA.DownPayment.Web.Controllers.AccountController.<GetLoginResultAsync>d__10.MoveNext() in d:\Dropbox_downpayment.org\NAEA.DownPayment.Web\Controllers\AccountController.cs:line 147 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at NAEA.DownPayment.Web.Controllers.AccountController.<Login>d__7.MoveNext() in d:\Dropbox\_downpayment.org\NAEA.DownPayment.Web\Controllers\AccountController.cs:line 100 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Abp.Threading.InternalAsyncHelper.<ReturnGenericTaskAfterAction>d__31.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) at System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag) at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag) at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. at System.Data.Entity.Internal.InternalContext.SaveChangesAsync(CancellationToken cancellationToken) at System.Data.Entity.Internal.LazyInternalContext.SaveChangesAsync(CancellationToken cancellationToken) at System.Data.Entity.DbContext.SaveChangesAsync(CancellationToken cancellationToken) at Abp.EntityFramework.AbpDbContext.SaveChangesAsync(CancellationToken cancellationToken) at System.Data.Entity.DbContext.SaveChangesAsync() at Abp.EntityFramework.Uow.EfUnitOfWork.<SaveChangesInDbContextAsync>d__a.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Abp.EntityFramework.Uow.EfUnitOfWork.<SaveChangesAsync>d__1.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at Abp.Authorization.Users.AbpUserManager3.<LoginAsync>d__37.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at NAEA.DownPayment.Web.Controllers.AccountController.<GetLoginResultAsync>d__10.MoveNext() in d:\Dropbox\_downpayment.org\NAEA.DownPayment.Web\Controllers\AccountController.cs:line 147 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at NAEA.DownPayment.Web.Controllers.AccountController.<Login>d__7.MoveNext() in d:\Dropbox_downpayment.org\NAEA.DownPayment.Web\Controllers\AccountController.cs:line 100 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Abp.Threading.InternalAsyncHelper.<ReturnGenericTaskAfterAction>d__31.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.GetResult() at System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) at System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag) at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.End() at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag) at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)

ok i dug in forums and found MyExceptionHandler and added to my project.

The reason its failing is because some of my required profile elements are showing as null on the model. Why would the login model care about that?

so i removed the [Required] attributes and it worked again.

This is how I had done it. In User.cs in .Core / Authorization / Users:

    [MaxLength(255)]
    [Required]
    public string Company { get; set; }

    [MaxLength(255)]
    [Required]
    public string Address { get; set; }

    [MaxLength(255)]
    [Required]
    public string City { get; set; }

    [MaxLength(10)]
    [Required]
    public string St { get; set; }

    [MaxLength(10)]
    [Required]
    [DataType(DataType.PostalCode)]
    public string Zip { get; set; }

    [Required]
    [MaxLength(25)]
    [DataType(DataType.PhoneNumber)]
    public string PhonePrimary { get; set; }

So since these are not set I guess somewhere on the login void in the boilerplate dll it causes login to not work. Is there away around this? It'd be preferred to me to have these required.

Well, it was just that those fields were required.

When I added them and did the migration after setting up the project it automatically set my existing users values to a blank string for all those values so none of them were null for sure (I had checked this after I did the migration because I was curious as to what it was going to do). It seems that the login doesn't bind the user appropriately if there have been new fields added to it perhaps.

It is odd that I'm getting a DbEntityValidationError though I thought because there isn't any sort of insert happening here, it should just be validating the creds, is there something beyond that happening I'm not aware of?

It's compiled into the dll so i really cant see what its doing exactly. This works for me for now, but it may be something you want to consider because the user object is very plain and most apps will have quite a bit of built onto that either directly on the table or adding a profile table.

Thanks, that worked. I didn't know that, like I said, this is a Data First to Code First lack of knowledge. I'm used to altering my table in sql then just refreshing my model =)

So I've added a geo service that has some handy geo lookup utils in it. What I'm trying to do from the home controller on a form submit to do the following.

        MyApp.Programs.IGeoAppService ga = new Programs.GeoAppService(new IRepository&lt;Programs.Geo&gt;());
        ga.GetCityFromZip(new GetGeoInput { Zip = "85210" });

but obviously new IRepository<Programs.Geo>()) is not allowed. Can you tell me how to properly access the service from a MVC controller?

Also, it would be handy if there was a way that abp could allow some publicly exposed services before the angular stuff comes in. is there some sort of config to do that?

So I tried this, but the action inside the service is error that DbContext has already been disposed.

private NAEA.DownPayment.Programs.IGeoAppService _geoService; public HomeController( IRepository<Geo> geoRepository) { _geoService = new GeoAppService(geoRepository); }

    public ActionResult Index()
    {
        _geoService.GetCityFromZip(new GetGeoInput { Zip = "85210" });
        return View();
    }

well i figured it out.

        var city = _geoRepository.Query&lt;Geo&gt;(a => a.Where(aa=> aa.Zip == input.Zip).FirstOrDefault());

cant use getall.

However, I did have my ActionResult annotated with [UnitOfWork]... why didnt that work? How do I ensure that db connection is open when coming into the repo?

I made a simple mailer like so: public class AppMailerService : DownPaymentAppServiceBase, IAppMailerService { private readonly IEmailSender _emailSender; private readonly ISmtpEmailSenderConfiguration _smtpConfig;

    public AppMailerService(ISmtpEmailSenderConfiguration smtpConfig, IEmailSender emailSender)
    {
        _smtpConfig = smtpConfig;
        _emailSender = emailSender;
    }


    public async Task SendSimpleMessageAsync(MailerInputDto input)
    {
        var smtpClient = new SmtpEmailSender(_smtpConfig).BuildClient();
        
        var from = new MailAddress(_smtpConfig.UserName);
        var msg = new MailMessage(from, new MailAddress(input.ToAddresses))
        {
            Subject = input.Subject,
            Body = input.Message,
            IsBodyHtml = true,

        };
        if (input.CCAddress != null)
        {
            msg.CC.Add(new MailAddress(input.CCAddress));
        }
        if (input.BCCAddress != null)
        {
            msg.Bcc.Add(new MailAddress(input.BCCAddress));
        }
        await _emailSender.SendAsync(msg, true);
       // smtpClient.Send(msg);
    }

}

I've noticed the await SendAsync seems to take a long time... 15 seconds-ish... is there a wait to skip the await method here? I don't care about server response since everything is being logged to database.

Thanks!

Showing 1 to 10 of 16 entries