public IEnumerable <TblPromotion> SearchPromotionList(DataTableModel dt, TblPromotion model, out int total_row) { ManagePromotionDa dataAccess = new ManagePromotionDa(); IEnumerable <TblPromotion> results = dataAccess.SearchPromotionList(dt, model, out total_row); return(results); }
public long UpdatePromotion(TblPromotion model) { long res = 0; // Declare new DataAccess object ManagePromotionDa dataAccess = new ManagePromotionDa(); using (var transaction = new TransactionScope()) { try { res = dataAccess.UpdatePromotion(model); if (res <= 0) { transaction.Dispose(); } transaction.Complete(); } catch (Exception ex) { throw new Exception(ex.Message, ex); } finally { transaction.Dispose(); } } return(res); }
public long UpdatePromotion(TblPromotion entity) { var pro = da.TblPromotion.Find(entity.id); if (pro != null) { try { // set data pro.PromotionName = entity.PromotionName; pro.PriceMin = entity.PriceMin; pro.PriceMax = entity.PriceMax; pro.Discount = entity.Discount; pro.del_flg = Constant.DeleteFlag.NON_DELETE; da.SaveChanges(); } catch (Exception ex) { throw ex; } } else { return(0); } return(entity.id); }
// GET: ManagePromotion #region REGISTER/ UPDATE public ActionResult PromotionEdit(long promotionId = 0) { CmnEntityModel currentUser = Session["CmnEntityModel"] as CmnEntityModel; if (currentUser == null || currentUser.IsAdmin == false) { return(RedirectToAction("Login", "Login")); } TblPromotion model = new TblPromotion(); CommonService comService = new CommonService(); ManagePromotionDa dataAccess = new ManagePromotionDa(); if (promotionId > 0) { var info = dataAccess.getPromotionByID(promotionId); if (info != null) { info.Discount = (int)info.Discount; model = info; } } return(View(model)); }
public long InsertPromotion(TblPromotion entity) { entity.del_flg = Constant.DeleteFlag.NON_DELETE; da.TblPromotion.Add(entity); da.SaveChanges(); return(entity.id); }
// GET: /AdminManageDistrict/ public ActionResult PromotionList() { CmnEntityModel currentUser = Session["CmnEntityModel"] as CmnEntityModel; if (currentUser == null || currentUser.IsAdmin == false) { return(RedirectToAction("Login", "Login")); } TblPromotion model = new TblPromotion(); CommonService comService = new CommonService(); return(View(model)); }
public ActionResult Edit(TblPromotion model) { try { using (ManagePromotionService service = new ManagePromotionService()) { if (ModelState.IsValid) { bool isNew = false; TblPromotion entity = new TblPromotion(); if (model.id == 0) { isNew = true; service.InsertPromotion(model); JsonResult result = Json(new { isNew = isNew }, JsonRequestBehavior.AllowGet); return(result); } else { isNew = false; service.UpdatePromotion(model); JsonResult result = Json(new { isNew = isNew }, JsonRequestBehavior.AllowGet); return(result); } } else { var ErrorMessages = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => new { x.Key, x.Value.Errors }).ToArray(); } return(new EmptyResult()); } } catch (Exception ex) { Response.StatusCode = (int)System.Net.HttpStatusCode.BadRequest; System.Web.HttpContext.Current.Session["ERROR"] = ex; return(new EmptyResult()); } }
public ActionResult List(DataTableModel dt, TblPromotion condition) { if (ModelState.IsValid) { using (ManagePromotionService service = new ManagePromotionService()) { int total_row = 0; var dataList = service.SearchPromotionList(dt, condition, out total_row); int order = 1; int totalRowCount = dataList.Count(); int lastItem = dt.iDisplayLength + dt.iDisplayStart; var result = Json( new { sEcho = dt.sEcho, iTotalRecords = total_row, iTotalDisplayRecords = total_row, aaData = (from i in dataList select new object[] { i.id, order++, i.PromotionName != null ? HttpUtility.HtmlEncode(i.PromotionName) : String.Empty, i.PriceMin, i.PriceMax, i.Discount.HasValue ? i.Discount.Value + "%" : "", i.Status == true? "Hiển thị" : "Ẩn", i.del_flg }) }); result.MaxJsonLength = Int32.MaxValue; return(result); } } return(new EmptyResult()); }
public IEnumerable <TblPromotion> SearchPromotionList(DataTableModel dt, TblPromotion model, out int total_row) { var lstPromotion = da.TblPromotion.Where(i => i.del_flg == model.del_flg); if (model.Status.HasValue) { lstPromotion = lstPromotion.Where(i => i.Status == model.Status); } // check giá nằm tron khoảng nào if (model.PriceMin > 0) { lstPromotion = lstPromotion.Where(i => i.PriceMin <= model.PriceMin && i.PriceMax > model.PriceMin); } if (!String.IsNullOrEmpty(model.PromotionName)) { lstPromotion = lstPromotion.Where(i => i.PromotionName.Contains(model.PromotionName)); } total_row = lstPromotion.Count(); lstPromotion = lstPromotion.OrderBy(i => i.del_flg).Skip(dt.iDisplayStart).Take(dt.iDisplayLength); return(lstPromotion); }
public TblPromotion getPromotionForDiscount(decimal priceTotal = 0) { TblPromotion pro = da.TblPromotion.Where(s => s.Status == true && s.del_flg == Constant.DeleteFlag.NON_DELETE && s.PriceMin <= priceTotal && s.PriceMax > priceTotal).SingleOrDefault(); return(pro); }
public TblPromotion getPromotionByID(long Id) { TblPromotion pro = da.TblPromotion.Where(s => s.id == Id).SingleOrDefault(); return(pro); }