public IHttpActionResult UpdateTender(int id, PublicTender tender) { if (!ModelState.IsValid) { return(BadRequest()); } var tenderInDB = _context.PublicTenders.SingleOrDefault(t => t.ID == id); if (tenderInDB == null) { return(NotFound()); } tenderInDB.SupplierID = tender.SupplierID; _context.SaveChanges(); return(Ok(tenderInDB)); }
public IHttpActionResult CreateTender(PublicTender tender) { //if (!ModelState.IsValid) // return BadRequest(); var subCat = _context.SubCategories.SingleOrDefault(sc => sc.ID == tender.SubCategoryID); if (subCat == null) { return(BadRequest()); } tender.Date = DateTime.Now; _context.PublicTenders.Add(tender); _context.SaveChanges(); var listOfSuppliers = new List <Supplier>(); var suppliers = _context.SupplierSubCategories.Include(s => s.Supplier).Include(sc => sc.SubCategory).ToList(); for (var i = 0; i < suppliers.Count; i++) { if (suppliers[i].SubCategoryID == subCat.ID) { _context.SupplierPublicTenders.Add(new SupplierPublicTender() { Date = DateTime.Now, PublicTenderID = tender.ID, PublicTender = tender, SupplierID = suppliers[i].SupplierID, Supplier = suppliers[i].Supplier }); _context.SaveChanges(); } } return(Created("/Home", tender)); }