public async Task <List <StockModel> > ProductSummaryDetails(ProductSummarySearchModel search) { // getting the yardid and then calling the stockget YardEntity yard = await(from yd in this.DbContext.Yards where yd.QuarryId == search.QuarryIds[0] select yd).SingleAsync(); return(await this.StockGet(yard.YardId, search.ProductTypeIds[0], search.MaterialColourIds[0], search.StartDate, search.EndDate)); }
public async Task QuarryUpdate(QuarryModel model) { await this.UpdateEntity <QuarryEntity, QuarryModel>(model, false); // getting the existing colours List <QuarryMaterialColourEntity> colours = await(from clr in this.DbContext.QuarryMaterialColours where clr.QuarryId == model.QuarryId select clr).ToListAsync(); // deleting colour ids colours.Where(c => !model.ColourIds.Contains(c.MaterialColourId)).ToList().ForEach(ce => this.DbContext.QuarryMaterialColours.Remove(ce)); // adding colours ids model.ColourIds.Except(colours.Select(ce => ce.MaterialColourId)).ToList().ForEach(cId => this.DbContext.QuarryMaterialColours.Add(new QuarryMaterialColourEntity() { QuarryId = model.QuarryId, MaterialColourId = cId })); // updating Yard YardEntity yard = await(from yd in this.DbContext.Yards where yd.QuarryId == model.QuarryId select yd).SingleAsync(); yard.Location = model.Location; yard.YardName = model.QuarryName + " Yard"; this.DbContext.Yards.Update(yard); await this.DbContext.SaveChangesAsync(); }
public async void YardUpdate() { // Arrange this.QuarryDbContext.Yards.AddRange( new YardEntity() { YardId = 1, YardName = "Central Yard", CompanyId = 1, DeletedInd = false }, new YardEntity() { YardId = 2, YardName = "NDB Central Yard", CompanyId = 1, DeletedInd = false }); await this.SaveChangesAsync(this.QuarryDbContext); YardModel model = new YardModel() { YardId = 2, YardName = "New Yard" }; // Act AjaxModel <NTModel> ajaxModel = await this.Controller.YardUpdate(model); // Assert YardEntity entity = this.QuarryDbContext.Yards.Where(e => e.YardId == 2).First(); Assert.Equal(entity.YardName, "New Yard"); Assert.Equal(ajaxModel.Message, QuarryMessages.YardSaveSuccess); }
public async void YardAdd() { // Arrange YardModel model = new YardModel() { YardId = 0, YardName = "Central Yard" }; // Act AjaxModel <NTModel> ajaxModel = await this.Controller.YardAdd(model); // Assert YardEntity entity = this.QuarryDbContext.Yards.Last(); Assert.Equal(entity.YardName, "Central Yard"); Assert.Equal(ajaxModel.Message, QuarryMessages.YardSaveSuccess); }
public async void QuarryAdd() { // Arrange this.QuarryDbContext.MaterialColours.AddRange( new MaterialColourEntity() { MaterialColourId = 1, ColourName = "White", CompanyId = 1, DeletedInd = false }, new MaterialColourEntity() { MaterialColourId = 2, ColourName = "Smoky", CompanyId = 1, DeletedInd = false }); await this.SaveChangesAsync(this.QuarryDbContext); QuarryModel model = new QuarryModel() { QuarryId = 0, QuarryName = "QM1", ColourIds = new List <int>() { 1, 2 } }; // Act AjaxModel <NTModel> ajaxModel = await this.Controller.QuarryAdd(model); // Assert QuarryEntity quarryEntity = this.QuarryDbContext.Quarries.Last(); Assert.Equal(quarryEntity.QuarryName, "QM1"); YardEntity yardEntity = this.QuarryDbContext.Yards.Last(); Assert.Equal(yardEntity.YardName, "QM1 Yard"); List <QuarryMaterialColourEntity> quarryColours = this.QuarryDbContext.QuarryMaterialColours.ToList(); Assert.Equal(quarryColours.Count, 2); Assert.Equal(quarryColours[1].MaterialColourId, 2); Assert.Equal(ajaxModel.Message, QuarryMessages.QuarrySaveSuccess); }
public async void QuarryDelete() { // Arrange this.QuarryDbContext.Quarries.AddRange( new QuarryEntity() { QuarryId = 1, QuarryName = "QM1", CompanyId = 1, DeletedInd = false }, new QuarryEntity() { QuarryId = 2, QuarryName = "QM2", CompanyId = 1, DeletedInd = false }); this.QuarryDbContext.Yards.AddRange( new YardEntity() { YardId = 1, YardName = "QM1 Yard", QuarryId = 1, CompanyId = 1, DeletedInd = false }, new YardEntity() { YardId = 2, YardName = "QM2 Yard", QuarryId = 2, CompanyId = 1, DeletedInd = false }); await this.SaveChangesAsync(this.QuarryDbContext); // Act AjaxModel <NTModel> ajaxModel = await this.Controller.QuarryDelete(2); // Assert QuarryEntity quarryEntity = this.QuarryDbContext.Quarries.Where(e => e.QuarryId == 2).First(); Assert.Equal(quarryEntity.DeletedInd, true); YardEntity yardEntity = this.QuarryDbContext.Yards.Where(e => e.QuarryId == 2).First(); Assert.Equal(yardEntity.DeletedInd, true); Assert.Equal(ajaxModel.Message, QuarryMessages.QuarryDeleteSuccess); }