public bool UpdateQuotation(PurchaseQuotation Quotation, IList <PurchaseQuotationItem> QuotationItemList, ref string ErrorMessage) { ErrorMessage = string.Empty; try { purchaseContext.Entry(Quotation).State = EntityState.Modified; purchaseContext.SaveChanges(); foreach (var model in QuotationItemList) { if (model.IsDummy == 1) { purchaseContext.Entry(model).State = EntityState.Deleted; purchaseContext.SaveChanges(); } else { if (model.Quote_Item_Id == 0) { model.Purchase_Quote_Id = Quotation.Purchase_Quote_Id; purchaseContext.PurchaseQuotationItem.Add(model); purchaseContext.SaveChanges(); } else { purchaseContext.Entry(model).State = EntityState.Modified; purchaseContext.SaveChanges(); } } } return(true); } catch (Exception ex) { ExceptionHandler.LogException(ex); ErrorMessage = ex.Message; return(false); } //catch (DbEntityValidationException dbEx) //{ // var errorList = new List<string>(); // foreach (var validationErrors in dbEx.EntityValidationErrors) // { // foreach (var validationError in validationErrors.ValidationErrors) // { // errorList.Add(String.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage)); // } // } // return false; //} }
public IHttpActionResult PutPurchase(int id, Purchase purchase) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != purchase.PurchaseId) { return(BadRequest()); } db.Entry(purchase).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PurchaseExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }