public IHttpActionResult UpdateTender(int id, PrivateTender tender) { if (!ModelState.IsValid) { return(BadRequest()); } var tenderInDB = _context.PrivateTenders.SingleOrDefault(t => t.ID == id); if (tenderInDB == null) { return(NotFound()); } tenderInDB.SupplierID = tender.SupplierID; _context.SaveChanges(); return(Ok(tenderInDB)); }
public IHttpActionResult CreateTender(PrivateTender tender) { if (!ModelState.IsValid) { return(BadRequest()); } var subCat = _context.SubCategories.SingleOrDefault(s => s.ID == tender.SubCategoryID); if (subCat == null) { return(BadRequest()); } ////tender.SubCategoryID = tender.SubCategory.ID; tender.Date = DateTime.Now; _context.PrivateTenders.Add(tender); _context.SaveChanges(); var listOfSuppliers = _context.SupplierSubCategories.ToList().FindAll(ssc => ssc.SubCategoryID == subCat.ID).Select(s => s.SupplierID); foreach (var supplier in listOfSuppliers) { _context.SupplierPrivateTenders.Add(new SupplierPrivateTender() { SupplierID = supplier, PrivateTenderID = tender.ID, Date = DateTime.Now }); } _context.SaveChanges(); return(Created("/Home", tender)); }