public void Add(DTOImport model) { if (model.InventoryId == 0 || model.EmployeeId == 0 || model.SupplierId == 0) { return; } Import Import = _mapper.Map <Import>(model); List <ImportDetail> ImportDetails = _mapper.Map <List <ImportDetail> >(model.ImportProductList); if (model.InventoryId > 0 && model.EmployeeId > 0) { Import.EmployeeId = model.EmployeeId; } _context.Add(Import); _context.SaveChanges(); if (ImportDetails != null) { foreach (var ed in ImportDetails) { ed.ImportId = Import.Id; double productPrice = _context.ProductPrices .Where(x => x.ProductId == ed.ProductId && !x.IsDeleted) .FirstOrDefault().Price; ed.Price = ed.Quantity * productPrice - (ed.Quantity * productPrice * ed.Discount / 100); } _context.AddRange(ImportDetails); _context.SaveChanges(); } }
public void Edit(DTOImport model) { Import Import = _mapper.Map <Import>(model); List <ImportDetail> newDetails = _mapper.Map <List <ImportDetail> >(model.ImportProductList); List <ImportDetail> oldDetails = _context.ImportDetails .Where(x => x.ImportId == model.Id).ToList(); _context.Update(Import); if (newDetails != null && newDetails.Count > 0) { _context.RemoveRange(oldDetails); if (newDetails != null) { foreach (var nd in newDetails) { nd.ImportId = Import.Id; double productPrice = _context.ProductPrices .Where(x => x.ProductId == nd.ProductId && !x.IsDeleted) .FirstOrDefault().Price; nd.Price = nd.Quantity * productPrice - (nd.Quantity * productPrice * nd.Discount / 100); } _context.AddRange(newDetails); } } _context.SaveChanges(); }
public DTOImport GetImportById(int idimport) { string query = string.Format("SELECT idimport,dayimport,supplier,nameimport,numbers,unitprice,idaccount FROM TableStaff WHERE idimport={0}", idimport); DataTable dt = DataProvider.Instance.ExecuteQuery(query); DTOImport gv = new DTOImport(dt.Rows[0]); return(gv); }
public IActionResult Details(int id) { DTOImport model = _unitOfWork.Imports.GetDetailsByIdDto(id); if (model != null) { return(PartialView("Details", model)); } return(RedirectToAction(nameof(Index))); }
public List <DTOImport> GetListImport() { List <DTOImport> list = new List <DTOImport>(); string query = string.Format("SELECT * FROM TableImport "); DataTable dt = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in dt.Rows) { DTOImport import = new DTOImport(item); list.Add(import); } return(list); }
public IActionResult SaveImport(DTOImport model) { if (model.Id == 0) { _unitOfWork.Imports.Add(model); } else { _unitOfWork.Imports.Edit(model); } return(RedirectToAction(nameof(Index))); }
public IActionResult EditImport(int id) { DTOImport model = _unitOfWork.Imports.GetByIdDto(id); model.Suppliers = _unitOfWork.Suppliers.GetAll() .Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); model.ImportDetails = _unitOfWork.Imports.GetImportDetails(id); return(View(model)); }
public IActionResult AddImport() { DTOImport model = new DTOImport { Inventories = _unitOfWork.Inventories.GetAll() .Select(x => new SelectListItem(x.Name, x.Id.ToString())).ToList(), Suppliers = _unitOfWork.Suppliers.GetAll() .Select(x => new SelectListItem(x.Name, x.Id.ToString())).ToList(), Employees = _unitOfWork.Employees.GetAll() .Select(x => new SelectListItem(x.Username, x.Id.ToString())).ToList() }; return(View("AddImport", model)); }
public DTOImport GetDetailsByIdDto(int ImportId) { Import Import = _context.Imports .Include(x => x.Inventory) .FirstOrDefault(x => x.Id == ImportId); if (Import == null) { return(null); } DTOImport model = _mapper.Map <DTOImport>(Import); model.ImportDetails = _context.ImportDetails .Where(x => x.ImportId == ImportId) .Include(x => x.Product).ToList(); model.Quantity = (int)model.ImportDetails.Sum(x => x.Quantity); model.TotalPrice = model.ImportDetails.Sum(x => x.Price); return(model); }