public async Task <bool> Add(ChemicalDto model) { var ink = _mapper.Map <Chemical>(model); ink.isShow = true; _repoChemical.Add(ink); return(await _repoInk.SaveAll()); }
public void Should_create_chemical() { _fakeRepository.GetMany(Arg.Any <Expression <Func <Chemical, bool> > >()).ReturnsForAnyArgs(x => new List <Chemical>()); _fakeRepository.Add(Arg.Do <Chemical>(x => x.Id = 1)).Returns(new Chemical { Id = 1 }); var chemical = _chemicalService.AddChemical("First", 110.99); Assert.That(chemical.Id, Is.EqualTo(1)); _fakeUnitOfWork.Received().SaveChanges(); }
public async Task ImportExcel(List <ChemicalForImportExcelDto> chemicalDtos) { try { var list = new List <ChemicalForImportExcelDto>(); var listChuaAdd = new List <ChemicalForImportExcelDto>(); var result = chemicalDtos.DistinctBy(x => new { x.Name, x.Process }).Where(x => x.Name != "").ToList(); foreach (var item in result) { var supname = await _repoSup.FindAll().FirstOrDefaultAsync(x => x.Name.ToUpper().Equals(item.Supplier.ToUpper())); if (supname != null) { item.SupplierID = supname.ID; } var process = await _repoProcess.FindAll().FirstOrDefaultAsync(x => x.Name.ToUpper().Equals(item.Process.ToUpper())); if (process != null) { item.ProcessID = process.ID; } // var ink = await AddInk(item); list.Add(item); } var listAdd = new List <Chemical>(); foreach (var ink in list) { if (!await CheckExistInk(ink)) { var inks = new Chemical(); inks.SupplierID = ink.SupplierID; inks.Code = ink.Code; inks.Name = ink.Name; inks.ProcessID = ink.ProcessID; inks.MaterialNO = ink.MaterialNO; inks.Unit = ink.Units; inks.CreatedDate = ink.CreatedDate; inks.CreatedBy = ink.CreatedBy; inks.DaysToExpiration = ink.DaysToExpiration; inks.isShow = true; inks.VOC = ink.VOC; inks.Modify = ink.Modify; if (ink.Modify == false) { inks.Percentage = 100; } _repoChemical.Add(inks); await _repoChemical.SaveAll(); listAdd.Add(inks); } else { listChuaAdd.Add(ink); } } var result1 = listAdd.Where(x => x.ID > 0).ToList(); var result2 = listAdd.Where(x => x.ID == 0).ToList(); } catch { throw; } }