public void Add(DTOExport model) { if (model.InventoryId == 0 || model.EmployeeId == 0 || model.CustomerId == 0) { return; } Export export = _mapper.Map <Export>(model); List <ExportDetail> exportDetails = _mapper.Map <List <ExportDetail> >(model.ExportProductList); if (model.InventoryId > 0 && model.EmployeeId > 0) { export.EmployeeId = model.EmployeeId; } _context.Add(export); _context.SaveChanges(); if (exportDetails != null) { foreach (var ed in exportDetails) { ed.ExportId = export.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(exportDetails); _context.SaveChanges(); } }
public void Edit(DTOExport model) { Export export = _mapper.Map <Export>(model); List <ExportDetail> newDetails = _mapper.Map <List <ExportDetail> >(model.ExportProductList); List <ExportDetail> oldDetails = _context.ExportDetails .Where(x => x.ExportId == model.Id).ToList(); _context.Update(export); if (newDetails != null && newDetails.Count > 0) { _context.RemoveRange(oldDetails); if (newDetails != null) { foreach (var nd in newDetails) { nd.ExportId = export.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 IActionResult Details(int id) { DTOExport model = _unitOfWork.Exports.GetDetailsByIdDto(id); if (model != null) { return(PartialView("Details", model)); } return(RedirectToAction(nameof(Index))); }
public IActionResult SaveExport(DTOExport model) { if (model.Id == 0) { _unitOfWork.Exports.Add(model); } else { _unitOfWork.Exports.Edit(model); } return(RedirectToAction(nameof(Index))); }
public IActionResult EditExport(int id) { DTOExport model = _unitOfWork.Exports.GetByIdDto(id); model.Customers = _unitOfWork.Customers.GetAll() .Select(x => new SelectListItem { Text = x.Name, Value = x.Id.ToString() }).ToList(); model.ExportDetails = _unitOfWork.Exports.GetExportDetails(id); return(View(model)); }
public IActionResult AddExport() { DTOExport model = new DTOExport { Inventories = _unitOfWork.Inventories.GetAll() .Select(x => new SelectListItem(x.Name, x.Id.ToString())).ToList(), Customers = _unitOfWork.Customers.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("AddExport", model)); }
public DTOExport GetDetailsByIdDto(int exportId) { Export export = _context.Exports .Include(x => x.Inventory) .FirstOrDefault(x => x.Id == exportId); if (export == null) { return(null); } DTOExport model = _mapper.Map <DTOExport>(export); model.ExportDetails = _context.ExportDetails .Where(x => x.ExportId == exportId) .Include(x => x.Product).ToList(); model.Quantity = (int)model.ExportDetails.Sum(x => x.Quantity); model.TotalPrice = model.ExportDetails.Sum(x => x.Price); return(model); }