public HttpResponseMessage updateDiscount(String id, Models.MstDiscount discount) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); var discounts = from d in db.MstDiscounts where d.Id == Convert.ToInt32(id) select d; if (discounts.Any()) { var updateDiscount = discounts.FirstOrDefault(); updateDiscount.Discount = discount.Discount; updateDiscount.DiscountRate = discount.DiscountRate; updateDiscount.IsInclusive = discount.IsInclusive; updateDiscount.AccountId = discount.AccountId; updateDiscount.IsLocked = discount.IsLocked; updateDiscount.UpdatedById = userId; updateDiscount.UpdatedDateTime = DateTime.Now; db.SubmitChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound)); } } catch { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }
public Int32 insertDiscount(Models.MstDiscount discount) { try { var userId = (from d in db.MstUsers where d.UserId == User.Identity.GetUserId() select d.Id).SingleOrDefault(); Data.MstDiscount newDiscount = new Data.MstDiscount(); newDiscount.Discount = discount.Discount; newDiscount.DiscountRate = discount.DiscountRate; newDiscount.IsInclusive = discount.IsInclusive; newDiscount.AccountId = discount.AccountId; newDiscount.IsLocked = discount.IsLocked; newDiscount.CreatedById = userId; newDiscount.CreatedDateTime = DateTime.Now; newDiscount.UpdatedById = userId; newDiscount.UpdatedDateTime = DateTime.Now; db.MstDiscounts.InsertOnSubmit(newDiscount); db.SubmitChanges(); return(newDiscount.Id); } catch { return(0); } }