public void Create(ProcurementTypeViewModel procurementVM) { var Procurement = new ProcurementType { ProcurementTypeName = procurementVM.ProcurementTypeName }; unitOfWork.ProcurementTypeRepository.Insert(Procurement); unitOfWork.Save(); }
public void Update(ProcurementTypeViewModel procurementVM) { var Procurement = new ProcurementType { ProcurementTypeId = procurementVM.ProcurementTypeId, ProcurementTypeName = procurementVM.ProcurementTypeName }; unitOfWork.ProcurementTypeRepository.Update(Procurement); unitOfWork.Save(); }
public void Delete(int id) { var Procurement = new ProcurementType { ProcurementTypeId = id }; unitOfWork.ProcurementTypeRepository.Delete(Procurement); unitOfWork.Save(); }
public async Task <IActionResult> Create(Procurement procurement, ProcurementType SelectedType) { procurement.ProcurementDate = System.DateTime.Today; procurement.Completed = false; if (SelectedType == ProcurementType.Manual) { procurement.ProcurementType = ProcurementType.Manual; } else { procurement.ProcurementType = ProcurementType.Automatic; } if (procurement.ProcurementType == ProcurementType.Manual) { if (ModelState.IsValid) { Procurement alreadyexist = _context.Procurements.Where(p => p.ProcurementType == ProcurementType.Manual).FirstOrDefault(p => p.Completed == false); if (alreadyexist == null) { _context.Add(procurement); await _context.SaveChangesAsync(); return(RedirectToAction("EditOrder", new { id = procurement.ProcurementID })); } else { ViewBag.ExistingOrder = "This is your existing order."; return(RedirectToAction("EditOrder", new { id = alreadyexist.ProcurementID })); } } } if (procurement.ProcurementType == ProcurementType.Automatic) { List <Book> books = new List <Book>(); books = _context.Books.Include(b => b.ProcurementDetails).Where(b => b.Inventory < b.Reorder).ToList(); if (books.Count == 0) { return(View("Error", new string[] { "There are currently no books below reorder point." })); } else { if (ModelState.IsValid) { _context.Add(procurement); await _context.SaveChangesAsync(); foreach (Book b in books) { ProcurementDetail procurementDetail = new ProcurementDetail(); procurementDetail.Quantity = 5; procurementDetail.BookPrice = b.Cost; procurementDetail.ExtendedPrice = procurementDetail.Quantity * procurementDetail.BookPrice; procurementDetail.Book = _context.Books.FirstOrDefault(o => o.BookID == b.BookID); procurementDetail.Procurement = _context.Procurements.FirstOrDefault(p => p.ProcurementID == procurement.ProcurementID); _context.Add(procurementDetail); await _context.SaveChangesAsync(); } return(RedirectToAction("EditOrder", new { id = procurement.ProcurementID })); } } } return(View("Create")); }