private List <Distributor> GetDummyDataDistributor() { var Org = new Organization() { Id = 12, FullName = "Org 1", Vat = "12324234", }; var user = new HealthInsUser() { Id = "a1", FullName = "User 1", UserName = "******" }; return(new List <Distributor>() { new Distributor() { Id = 12, Organization = Org, FullName = "Dist1", User = user }, new Distributor() { Id = 13, Organization = Org, FullName = "Dist2", User = user, } }); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = "/Identity/Account/Login"; if (ModelState.IsValid) { var isRoot = !_userManager.Users.Any(); var user = new HealthInsUser { UserName = Input.UserName, Email = Input.Email }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { if (isRoot) { await _userManager.AddToRoleAsync(user, "Admin"); } else { await _userManager.AddToRoleAsync(user, "User"); } #region Email Functionality //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.Page( // "/Account/ConfirmEmail", // pageHandler: null, // values: new { userId = user.Id, code = code }, // protocol: Request.Scheme); //await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", // $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); #endregion this.TempData["info"] = String.Format(REGISTER_OK); return(Redirect(returnUrl)); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } if (result.Errors.Any()) { this.TempData["error"] = String.Format(result.Errors.First().Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <bool> Update(DistributorServiceModel distributorServiceModel) { Distributor distDB = this.context.Distributors.SingleOrDefault(p => p.Id == distributorServiceModel.Id); HealthInsUser user = this.context.Users.SingleOrDefault(p => p.UserName == distributorServiceModel.UserUserName); Organization org = this.context.Organizations.SingleOrDefault(p => p.Id == distributorServiceModel.OrganizationId); distDB.User = user; distDB.Organization = org; distDB.FullName = distributorServiceModel.FullName; context.Update(distDB); int result = await context.SaveChangesAsync(); return(result > 0); }
public async Task <bool> Create(DistributorServiceModel distributorServiceModel) { Distributor distributor = AutoMapper.Mapper.Map <Distributor>(distributorServiceModel); HealthInsUser user = this.context.Users.SingleOrDefault(p => p.UserName == distributorServiceModel.UserUserName); Organization org = this.context.Organizations.SingleOrDefault(p => p.Id == distributorServiceModel.OrganizationId); distributor.User = user; distributor.Organization = org; context.Distributors.Add(distributor); int result = await context.SaveChangesAsync(); distributorServiceModel.Id = distributor.Id; return(result > 0); }
public async Task Create_ShouldReturnCorrectResults() { string errorMessagePrefix = "DistributorService Create(DistributorServiceModel) method does not work properly."; var context = HealthInsDbContextInMemoryFactory.InitializeContext(); this.distributorService = new DistributorService(context); await SeedData(context); var org = new Organization() { Id = 21, FullName = "Org 2", Vat = "1232423455", }; var user = new HealthInsUser() { Id = "a2", FullName = "User 2", UserName = "******" }; await context.AddAsync(org); await context.AddAsync(user); await context.SaveChangesAsync(); DistributorServiceModel newDist = new DistributorServiceModel() { Id = 14, OrganizationId = org.Id, FullName = "Dist3", UserUserName = user.UserName, }; var actualResults = await this.distributorService.Create(newDist); var actualEntry = this.distributorService.GetById(14); Assert.True(newDist.FullName == actualEntry.FullName, errorMessagePrefix + " " + "FullName is not returned properly."); Assert.True(newDist.OrganizationId == actualEntry.OrganizationId, errorMessagePrefix + " " + "Organization is not returned properly."); Assert.True(actualEntry.Organization != null, errorMessagePrefix + " " + "Organization is not returned properly."); Assert.True(newDist.UserUserName == actualEntry.UserUserName, errorMessagePrefix + " " + "User is not returned properly."); Assert.True(actualEntry.User != null, errorMessagePrefix + " " + "User is not returned properly."); }
public async Task Update_ShouldReturnCorrectResults() { string errorMessagePrefix = "DistributorService Update(DistributorServiceModel) method does not work properly."; var context = HealthInsDbContextInMemoryFactory.InitializeContext(); this.distributorService = new DistributorService(context); await SeedData(context); var persons = context.Persons.ToList(); var user2 = new HealthInsUser() { Id = "a155", FullName = "User 155", UserName = "******" }; var org2 = new Organization() { Id = 155, FullName = "Org 155", Vat = "123242342", }; await context.AddAsync(org2); await context.AddAsync(user2); await context.SaveChangesAsync(); DistributorServiceModel dist = context.Distributors.First().To <DistributorServiceModel>(); dist.FullName = "Dist 123"; dist.OrganizationId = 155; dist.UserUserName = "******"; var actualResults = await this.distributorService.Update(dist); var actualEntry = this.distributorService.GetById(dist.Id); Assert.True(dist.FullName == actualEntry.FullName, errorMessagePrefix + " " + "FullName is not returned properly."); Assert.True(dist.OrganizationId == actualEntry.OrganizationId, errorMessagePrefix + " " + "Organization is not returned properly."); Assert.True(dist.UserUserName == dist.UserUserName, errorMessagePrefix + " " + "User is not returned properly."); }