public ActionResult ToOffer(OfferExp expData) { string userId = User.Identity.GetUserId(); bool result = true; using (PriceDataModel2 db = new PriceDataModel2()) { OfferMas basket = db.OfferMas.FirstOrDefault(a => a.ReferenceNo == expData.Reference && a.Status == 0 && a.User == userId); if (basket == null) { result = false; } else { basket.Exp1 = expData.Exp1; basket.Exp2 = expData.Exp2; basket.Status = 1; db.SaveChanges(); } } return(Json(new { success = result })); }
public ActionResult Index(OfferDet basket) { var user = User.Identity.GetUserId(); using (PriceDataModel2 db = new PriceDataModel2()) { var basketMas = db.OfferMas.SingleOrDefault(a => a.User == user && a.IsActive && a.Status == 0); if (basketMas == null) { var userCard = userManager.Users.FirstOrDefault(a => a.Id == user); var lastindex = db.Reference.FirstOrDefault(c => c.StoreId == userCard.StoreId && c.Type == "Offer"); if (lastindex == null) { Reference lastindex1 = new Reference(); lastindex1.StoreId = userCard.StoreId; lastindex1.Type = "Offer"; lastindex1.LastReference = 1; lastindex = lastindex1; lastindex.LastReference += 1; db.Reference.Add(lastindex1); db.SaveChanges(); } else { lastindex.LastReference += 1; db.SaveChanges(); } var store = db.Stores.FirstOrDefault(a => a.Id == userCard.StoreId); OfferMas bmas = new OfferMas(); bmas.User = user; bmas.Store = store; bmas.IsActive = true; bmas.IsDeleted = false; bmas.RevisionId = 0; bmas.Date = DateTime.Now; string lastindex2 = "000000" + lastindex.LastReference; bmas.ReferenceNo = "LM" + store.StoreCode + lastindex2.Substring(lastindex2.Length - 6, 6); basket.OfferMas = bmas; db.OfferDet.Add(basket); db.SaveChanges(); } else { basket.BasketMas_ID = basketMas.ID; basketMas.Date = DateTime.Now; db.OfferDet.Add(basket); db.SaveChanges(); } } return(Json(new { success = true })); }