public async Task<int> EditCompanyAsync(AddAndEditCompanyBindingModel model) { var company = this.Mapper.Map<Company>(model); this.DbContext.Companies.Update(company); await this.DbContext.SaveChangesAsync(); return company.Id; }
public async Task <IActionResult> Add(AddAndEditCompanyBindingModel model) { if (!ModelState.IsValid) { this.TempData["__MessageType"] = MessageType.Warning; this.TempData["__MessageText"] = Constants.ErrorMessages.InvalidFormData; return(View(model)); } var id = await this.companyService.AddCompanyAsync(model); this.TempData["__MessageType"] = MessageType.Success; this.TempData["__MessageText"] = Constants.SuccessMessages.CompanyAdded; return(this.RedirectToAction("Details", new { companyId = id })); }
public async Task CompanyService_AddCompany() { AddAndEditCompanyBindingModel model = new AddAndEditCompanyBindingModel() { Name = "STP", Description = "Some description" }; AutoMapper.Mapper.Initialize(config => config.AddProfile <AutoMapperProfile>()); var service = new CompanyService(dbContext, AutoMapper.Mapper.Instance); await service.AddCompanyAsync(model); Assert.IsNotNull(dbContext.Companies.FirstOrDefault(c => c.Name == "STP")); Assert.IsNotNull(dbContext.Companies.FirstOrDefault(c => c.Description == "Some description")); }
public async Task CompanyService_CompanyDetails() { AddAndEditCompanyBindingModel model = new AddAndEditCompanyBindingModel() { Id = 1, Name = "STPDelete", Description = "Some description" }; dbContext.SaveChanges(); var service = new CompanyService(dbContext, AutoMapper.Mapper.Instance); await service.AddCompanyAsync(model); Assert.IsNotNull(dbContext.Companies.FirstOrDefault(c => c.Name == "STPDelete")); Assert.IsNotNull(dbContext.Companies.FirstOrDefault(c => c.Description == "Some description")); var companyDetailsModel = await service.CompanyDetailsAsync(1); Assert.AreEqual(companyDetailsModel.Name, dbContext.Companies.Find(1).Name); Assert.AreEqual(companyDetailsModel.Description, dbContext.Companies.Find(1).Description); }
public async Task CompanyService_DeleteCompany() { AddAndEditCompanyBindingModel model = new AddAndEditCompanyBindingModel() { Id = 1, Name = "STPDelete", Description = "Some description" }; dbContext.SaveChanges(); var service = new CompanyService(dbContext, AutoMapper.Mapper.Instance); await service.AddCompanyAsync(model); Assert.IsNotNull(dbContext.Companies.FirstOrDefault(c => c.Name == "STPDelete")); Assert.IsNotNull(dbContext.Companies.FirstOrDefault(c => c.Description == "Some description")); await service.DeleteCompanyAsync(1); Assert.IsNull(dbContext.Companies.FirstOrDefault(c => c.Name == "STPDelete")); Assert.IsNull(dbContext.Companies.FirstOrDefault(c => c.Description == "Some other description")); }