public ActionResult UpdatePost(OffersInfo oOffersInfo, HttpPostedFileBase ctrlPostImage, FormCollection updateFormCollection, string chkIsActive) { try { if (ModelState.IsValid) { oSysCurrentUser = (SysUser)Session["User"]; var offerUpdate = oDBContext.OffersInfoes.FirstOrDefault(t => t.ID == oOffersInfo.ID); var uploadFileName = ""; if (offerUpdate != null && SaveAvailableOutlet(updateFormCollection, offerUpdate.ID.ToString())) { offerUpdate.PostName = oOffersInfo.PostName; offerUpdate.OfferDiscountAmt = oOffersInfo.OfferDiscountAmt; offerUpdate.OfferStartDate = oOffersInfo.OfferStartDate; offerUpdate.OfferEndDate = oOffersInfo.OfferEndDate; offerUpdate.OfferCat = oOffersInfo.OfferCat; offerUpdate.OfferLoc = oOffersInfo.OfferLoc; offerUpdate.OfferDetails = oOffersInfo.OfferDetails; if (IsCurrentUserAdmin()) { offerUpdate.OfferFeatureVal = oOffersInfo.OfferFeatureVal.Value; } offerUpdate.IsActive = (!string.IsNullOrEmpty(chkIsActive) && chkIsActive.Contains("on")) ? true : false; if (Request.Files["ctrlPostImage"].ContentLength > 0) { if (ctrlPostImage != null) { uploadFileName = DateTime.Now.ToString("yyddMMhhmmssfff") + "_" + Path.GetFileName(ctrlPostImage.FileName).Replace(" ", "").ToLower().Trim(); offerUpdate.OfferImagePath = postImagePath + uploadFileName; ctrlPostImage.SaveAs(Path.Combine(Server.MapPath(postImagePath), uploadFileName)); } else { offerUpdate.OfferImagePath = postImagePath + defaultImageFileName; } } else { offerUpdate.OfferImagePath = offerUpdate.OfferImagePath; } offerUpdate.ModifiedBy = oSysCurrentUser.ID; offerUpdate.ModifiedOn = DateTime.Now; oDBContext.SaveChanges(); TempData["SuccessMsg"] = "Data Updated Successfully"; } else { TempData["ErrorMsg"] = "Data Not Found!!!"; } } } catch (Exception ex) { TempData["ErrorMsg"] = "Error Occured Due to " + ExceptionMsg(ex); } return(RedirectToAction("Index")); }
public ActionResult InsertPost(OffersInfo oOffersInfo, HttpPostedFileBase ctrlPostImage, FormCollection newFormCollection) { try { if (ModelState.IsValid) { oSysCurrentUser = (SysUser)Session["User"]; var offerNew = oDBContext.OffersInfoes.FirstOrDefault(t => t.ID == oOffersInfo.ID); var uploadFileName = ""; if (offerNew == null) { offerNew = new OffersInfo(); offerNew.PostName = oOffersInfo.PostName; offerNew.OfferDiscountAmt = oOffersInfo.OfferDiscountAmt; offerNew.OfferStartDate = oOffersInfo.OfferStartDate; offerNew.OfferEndDate = oOffersInfo.OfferEndDate; offerNew.OfferCat = oOffersInfo.OfferCat; offerNew.OfferLoc = oOffersInfo.OfferLoc; offerNew.OfferDetails = oOffersInfo.OfferDetails; offerNew.OfferFeatureVal = oOffersInfo.OfferFeatureVal; if (ctrlPostImage != null) { uploadFileName = DateTime.Now.ToString("yyddMMhhmmssfff") + "_" + Path.GetFileName(ctrlPostImage.FileName).Replace(" ", "").ToLower().Trim(); offerNew.OfferImagePath = postImagePath + uploadFileName; ctrlPostImage.SaveAs(Path.Combine(Server.MapPath(postImagePath), uploadFileName)); } else { offerNew.OfferImagePath = postImagePath + defaultImageFileName; } offerNew.CreatedBy = oSysCurrentUser.ID; offerNew.CreatedOn = DateTime.Now;; offerNew.IsActive = oOffersInfo.IsActive; offerNew.OfferStatus = oOffersInfo.OfferStatus; oDBContext.OffersInfoes.Add(offerNew); oDBContext.SaveChanges(); SaveAvailableOutlet(newFormCollection, offerNew.ID.ToString()); TempData["SuccessMsg"] = "Data Saved Successfully"; } else { TempData["ErrorMsg"] = "Data already Exists!!!"; } } } catch (Exception ex) { TempData["ErrorMsg"] = "Error Occured Due to " + ExceptionMsg(ex); } return(RedirectToAction("Index")); }
public ActionResult GetPostDetail(string postId) { oCurrentUser = (SysUser)Session["User"]; OffersInfo oOffersInfo = new OffersInfo(); if (!string.IsNullOrEmpty(postId)) { var enumFeature = Convert.ToInt32(Enumaretion.DBEnumType.OfferFeature); var lowFeature = oDBContext.SysEnums.FirstOrDefault(t => t.EnumType == enumFeature && t.EnumName.ToLower().Contains("low")).ID; oOffersInfo = oDBContext.OffersInfoes.FirstOrDefault(t => t.ID.ToString() == postId); ViewBag.CatList = oDBContext.OfferCategories.Where(t => t.IsActive).Select(x => x).ToList().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.CategoryName.ToString() }); if (!IsCurrentUserAdmin()) { ViewBag.LocList = oDBContext.OfferLocOutletMaps.Where(t => t.IsActive && t.SysUser.ID == oCurrentUser.ID).Select(x => x.OfferLocation).Distinct().ToList().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.LocationName.ToString() }); } else { ViewBag.LocList = oDBContext.OfferLocOutletMaps.Where(t => t.IsActive).Select(x => x.OfferLocation).Distinct().ToList().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.LocationName.ToString() }); } if (IsCurrentUserAdmin()) { ViewBag.FeatureList = oDBContext.SysEnums.Where(t => t.EnumType == enumFeature).Select(x => x).Distinct().ToList().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.EnumName.ToString() }); } else { ViewBag.FeatureList = oDBContext.SysEnums.Where(t => t.EnumType == enumFeature && t.EnumName.ToLower().Contains("low")).Select(x => x).Distinct().ToList().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.EnumName.ToString() }); } } return(PartialView("_postDetailPartial", oOffersInfo)); }
public OffersElementBuilder() { _offers = new OffersInfo(); }
public OffersElement(OffersInfo offers) { _offers = offers; }
public ActionResult NewPost() { oCurrentUser = (SysUser)Session["User"]; var newPost = new OffersInfo(); if (Session["User"] != null) { var enumFeature = Convert.ToInt32(Enumaretion.DBEnumType.OfferFeature); var lowFeature = oDBContext.SysEnums.FirstOrDefault(t => t.EnumType == enumFeature && t.EnumName.ToLower().Contains("low")).ID; oSysCurrentUser = (SysUser)Session["User"]; newPost.OfferFeatureVal = lowFeature; newPost.IsActive = false; newPost.CreatedBy = oSysCurrentUser.ID; newPost.CreatedOn = DateTime.Now; newPost.OfferStatus = 1; //hardcode for offer status newPost.OfferStartDate = DateTime.Now; newPost.OfferEndDate = DateTime.Now; ViewBag.CatList = oDBContext.OfferCategories.Where(t => t.IsActive).Select(x => x).ToList().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.CategoryName.ToString() }); if (!IsCurrentUserAdmin()) { ViewBag.LocList = oDBContext.OfferLocOutletMaps.Where(t => t.IsActive && t.SysUser.ID == oCurrentUser.ID).Select(x => x.OfferLocation).Distinct().ToList().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.LocationName.ToString() }); } else { ViewBag.LocList = oDBContext.OfferLocOutletMaps.Where(t => t.IsActive).Select(x => x.OfferLocation).Distinct().ToList().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.LocationName.ToString() }); } if (IsCurrentUserAdmin()) { ViewBag.FeatureList = oDBContext.SysEnums.Where(t => t.EnumType == enumFeature).Select(x => x).ToList().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.EnumName.ToString() }); } else { ViewBag.FeatureList = oDBContext.SysEnums.Where(t => t.EnumType == enumFeature && t.EnumName.ToLower().Contains("low")).Select(x => x).ToList().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.EnumName.ToString() }); } return(PartialView("_createPostPartial", newPost)); } else { return(RedirectToAction("SignIn", "SignIn")); } }