public void UpdateAsync_Return_Success() { string testName = GetCurrentMethod(); var dbContext = _dbContext(testName); IIdentityService identityService = new IdentityService { Username = "******" }; var model = new RO_Garment_SizeBreakdown() { Code = "Code", RO_Garment_SizeBreakdown_Details = new List <RO_Garment_SizeBreakdown_Detail>() { new RO_Garment_SizeBreakdown_Detail() { Information = "Information" } } }; dbContext.RO_Garment_SizeBreakdowns.Add(model); dbContext.SaveChanges(); ROGarmentSizeBreakdownLogic unitUnderTest = new ROGarmentSizeBreakdownLogic(GetServiceProvider(testName).Object, identityService, dbContext); unitUnderTest.UpdateAsync(model.Id, model); }
public override void OnUpdating(int id, RO_Garment model) { HashSet <int> RO_Garment_SizeBreakdowns = new HashSet <int>(this.RO_Garment_SizeBreakdownService.DbSet .Where(p => p.RO_GarmentId.Equals(id)) .Select(p => p.Id)); foreach (int RO_Garment_SizeBreakdown in RO_Garment_SizeBreakdowns) { RO_Garment_SizeBreakdown childModel = model.RO_Garment_SizeBreakdowns.FirstOrDefault(prop => prop.Id.Equals(RO_Garment_SizeBreakdown)); if (childModel == null) { this.RO_Garment_SizeBreakdownService.Deleting(RO_Garment_SizeBreakdown); } else { this.RO_Garment_SizeBreakdownService.Updating(RO_Garment_SizeBreakdown, childModel); } } foreach (RO_Garment_SizeBreakdown RO_Garment_SizeBreakdown in model.RO_Garment_SizeBreakdowns) { if (RO_Garment_SizeBreakdown.Id.Equals(0)) { this.RO_Garment_SizeBreakdownService.Creating(RO_Garment_SizeBreakdown); } } base.OnUpdating(id, model); }
public RO_Garment MapToModel(RO_GarmentViewModel viewModel) { RO_Garment model = new RO_Garment(); PropertyCopier <RO_GarmentViewModel, RO_Garment> .Copy(viewModel, model); model.ImagesPath = viewModel.ImagesPath != null?JsonConvert.SerializeObject(viewModel.ImagesPath) : null; model.CostCalculationGarmentId = viewModel.CostCalculationGarment.Id; model.CostCalculationGarment = this.CostCalculationGarmentService.MapToModel(viewModel.CostCalculationGarment); model.ImagesName = JsonConvert.SerializeObject(viewModel.ImagesName); model.RO_Garment_SizeBreakdowns = new List <RO_Garment_SizeBreakdown>(); foreach (RO_Garment_SizeBreakdownViewModel sizeBreakdownVM in viewModel.RO_Garment_SizeBreakdowns) { RO_Garment_SizeBreakdown sizeBreakdown = this.RO_Garment_SizeBreakdownService.MapToModel(sizeBreakdownVM); model.RO_Garment_SizeBreakdowns.Add(sizeBreakdown); } return(model); }
public override void UpdateAsync(long id, RO_Garment model) { if (model.RO_Garment_SizeBreakdowns != null) { HashSet <long> detailIds = roGarmentSizeBreakdownLogic.GetIds(id); foreach (var itemId in detailIds) { RO_Garment_SizeBreakdown data = model.RO_Garment_SizeBreakdowns.FirstOrDefault(prop => prop.Id.Equals(itemId)); if (data == null) { RO_Garment_SizeBreakdown dataItem = DbContext.RO_Garment_SizeBreakdowns.FirstOrDefault(prop => prop.Id.Equals(itemId)); List <RO_Garment_SizeBreakdown_Detail> details = DbContext.RO_Garment_SizeBreakdown_Details.Where(a => a.RO_Garment_SizeBreakdownId.Equals(itemId)).ToList(); foreach (RO_Garment_SizeBreakdown_Detail detail in details) { EntityExtension.FlagForDelete(detail, IdentityService.Username, "sales-service"); } EntityExtension.FlagForDelete(dataItem, IdentityService.Username, "sales-service"); } else { roGarmentSizeBreakdownLogic.UpdateAsync(itemId, data); } foreach (RO_Garment_SizeBreakdown item in model.RO_Garment_SizeBreakdowns) { if (item.Id == 0) { roGarmentSizeBreakdownLogic.Create(item); } } } } EntityExtension.FlagForUpdate(model, IdentityService.Username, "sales-service"); DbSet.Update(model); }
public void Read_With_EmptyKeyword_Return_Success() { string testName = GetCurrentMethod(); var dbContext = _dbContext(testName); IIdentityService identityService = new IdentityService { Username = "******" }; var model = new RO_Garment_SizeBreakdown() { Code = "Code" }; dbContext.RO_Garment_SizeBreakdowns.Add(model); dbContext.SaveChanges(); ROGarmentSizeBreakdownLogic unitUnderTest = new ROGarmentSizeBreakdownLogic(GetServiceProvider(testName).Object, identityService, dbContext); var result = unitUnderTest.Read(1, 1, "{}", new List <string>() { "" }, null, "{}"); Assert.True(0 < result.Data.Count); Assert.NotEmpty(result.Data); }