public AdOptionModel GetSpecialDetail(string specialAdoption) { AdOptionModel model = new AdOptionModel(); try { #region get detail model = UnitofWork.RepoAdOption.Where(x => x.SpecialChoice == specialAdoption).Select(x => new AdOptionModel { ADOptionName = x.ADOptionName, MinimumCirculation = x.MinimumCirculation, Vendorname = x.Vendorname, ADOptionID = x.ADOptionID, IsActive = x.Inactive ?? true, SpecialChoice = x.SpecialChoice, }).FirstOrDefault(); #endregion if (model != null) { model.EncryptedID = model.ADOptionID.ToString().ToEnctypt(); } else { model = new AdOptionModel(); } } catch (Exception ex) { EventLogHandler.WriteLog(ex); } return(model); }
public ActionResult Save(AdOptionModel model) { TransactionMessage TransMessage = new TransactionMessage(); TransMessage.Status = MessageStatus.Error; try { if (ModelState.IsValid) { if (model.EncryptedID.IsValidEncryptedID() && model.EncryptedID.ToDecrypt().IsNumber()) { model.ADOptionID = Convert.ToInt32(model.EncryptedID.ToDecrypt()); } model = _AdOption.Save(model); if (model.TransMessage.Status == MessageStatus.Success) { SuccessNotification(model.TransMessage.Message); } } else { TransMessage.Message = utilityHelper.ReadGlobalMessage("AdOption", "ErrorMessage"); } } catch (Exception ex) { // write exception log EventLogHandler.WriteLog(ex); } return(Json(model.TransMessage, JsonRequestBehavior.DenyGet)); }
public ActionResult Add(string id) { AdOptionModel model = new AdOptionModel(); if (id != null) { model = _AdOption.GetDetail(id); } ViewBag.SpecialList = _common.GetAdoptionList(); return(View(model)); }
/// <summary> /// to save or update Page /// </summary> /// <param name="model">UsersModel</param> /// <returns>UsersModel</returns> public AdOptionModel Save(AdOptionModel model) { model.TransMessage = new TransactionMessage(); model.TransMessage.Status = MessageStatus.Error; try { #region check duplicate if (UnitofWork.RepoAdOption.Where(x => x.ADOptionName == model.ADOptionName && x.ADOptionID != model.ADOptionID).Count() > 0) { model.TransMessage.Message = utilityHelper.ReadGlobalMessage("AdOption", "Duplicate"); return(model); } #endregion #region check duplicate Specail Ad option if (model.SpecialChoice != null) { if (UnitofWork.RepoAdOption.Where(x => x.Inactive == true && x.SpecialChoice == model.SpecialChoice && x.ADOptionID != model.ADOptionID).Count() > 0) { model.TransMessage.Message = utilityHelper.ReadGlobalMessage("AdOption", "SpecialDuplicate"); return(model); } } #endregion ADOption dbAdOption = UnitofWork.RepoAdOption.Where(x => x.ADOptionID == model.ADOptionID).FirstOrDefault(); bool isSave = false; if (dbAdOption == null) { #region Save dbAdOption = new ADOption(); UnitofWork.RepoAdOption.Add(dbAdOption); model.TransMessage.Message = utilityHelper.ReadGlobalMessage("AdOption", "Save"); isSave = true; #endregion } else { #region Update model.TransMessage.Message = utilityHelper.ReadGlobalMessage("AdOption", "Update"); #endregion } #region Set Value dbAdOption.ADOptionName = model.ADOptionName; dbAdOption.MinimumCirculation = model.MinimumCirculation; dbAdOption.Vendorname = model.Vendorname; dbAdOption.Inactive = model.IsActive; dbAdOption.SpecialChoice = model.SpecialChoice; #endregion UnitofWork.Commit(); model.TransMessage.Status = MessageStatus.Success; } catch (Exception ex) { EventLogHandler.WriteLog(ex); } return(model); }
public ActionResult Next(List <StoreAdChoiceModel> model) { TransactionMessage TransMessage = new TransactionMessage(); TransMessage.Status = MessageStatus.Error; TransMessage.Message = "Next step is in progress"; string msg = ""; int counter = 0; int i = 0; try { if (model != null) { List <StoreAdChoiceModel> list = new List <StoreAdChoiceModel>(); if (SessionHelper.SessionForModel != null && SessionHelper.SessionForModel.GetType() == typeof(List <StoreAdChoiceModel>)) { list = (List <StoreAdChoiceModel>)SessionHelper.SessionForModel; } #region Validation foreach (var item in model) { //set default value list[i].CouponID = 0; list[i].CouponName = ""; list[i].FollowedCorporate = false; list[i].NotPrinting = false; list[i].OwnDistribution = false; list[i].ADOptionName = ""; list[i].CouponName = ""; list[i].UserAdChoice = item.UserAdChoice; // validate switch (item.UserAdChoice) { #region FollowCorporate case UserAdChoice.FollowCorporate: item.FollowedCorporate = true; list[i].FollowedCorporate = true; list[i].AdOptionID = list[i].AdMonthDetail.AdOptionID; list[i].ADOptionName = list[i].AdMonthDetail.AdOptionName; list[i].AdCouponID = list[i].AdMonthDetail.AdCouponID; list[i].AdCouponName = list[i].AdMonthDetail.AdCouponName; list[i].CouponID = list[i].AdMonthDetail.AdCouponID; break; #endregion #region IndividualChoice case UserAdChoice.IndividualChoice: //if (item.SelectedAdOption != null && item.SelectedAdOption.Count() > 0) //{ // list[i].SelectedAdOption = item.SelectedAdOption; // list[i].ADOptionName = list[i].AdOptionList.Where(x => item.SelectedAdOption.Where(s => s.ToString() == x.Value).Count() > 0).Select(x => x.Text).ToArray().ToString(); // list[i].AdOptionList.ForEach(x => x.Selected = false); // foreach (var ad in item.SelectedAdOption) // { // list[i].AdOptionID = ad; // todo: right now only a single ad option is saving. // list[i].ADOptionName += list[i].AdOptionList.Where(x => x.Value == ad.ToString()).FirstOrDefault().Text + ", "; // list[i].AdOptionList.Where(x => x.Value == ad.ToString()).FirstOrDefault().Selected = true; // //list[i].StoreAdOptionList.Where(x => x.Value == ad.ToString()).FirstOrDefault().Selected = true; // } // //if (!string.IsNullOrEmpty(list[i].ADOptionName) && list[i].ADOptionName.Contains(", ")) // //{ // // list[i].ADOptionName = list[i].ADOptionName.Substring(0, list[i].ADOptionName.Length - 2); // //} //} if (item.AdOptionID > 0) { list[i].AdOptionID = item.AdOptionID; list[i].ADOptionName = list[i].AdOptionList.Where(x => x.Value == item.AdOptionID.ToString()).FirstOrDefault().Text; list[i].AdOptionList.Where(x => x.Value == item.AdOptionID.ToString()).FirstOrDefault().Selected = true; //list[i].InHomeDate = item.InHomeDate; #region check coupon is selected or not if (item.IsCouponApply.HasValue) // check is select yes/no { list[i].IsCouponApply = item.IsCouponApply.Value; if (item.IsCouponApply.Value) // if choose yes then { if (item.CouponID > 0) { list[i].CouponID = item.CouponID; list[i].CouponName = list[i].CouponList.Where(x => x.Value == item.CouponID.ToString()).FirstOrDefault().Text; list[i].CouponList.ForEach(x => x.Selected = false); list[i].CouponList.Where(x => x.Value == item.CouponID.ToString()).FirstOrDefault().Selected = true; } else { counter++; msg += utilityHelper.ReadGlobalMessage("StoreAdChoice", "ChooseCoupon").Replace("[Store]", item.StoreID.ToString()) + "<br>"; } } } else { counter++; msg += utilityHelper.ReadGlobalMessage("StoreAdChoice", "YesNo").Replace("[Store]", item.StoreID.ToString()) + "<br>"; } #endregion } else { counter++; msg += utilityHelper.ReadGlobalMessage("StoreAdChoice", "IndividualChoice").Replace("[Store]", item.StoreID.ToString()) + "<br>"; } break; #endregion #region NotPrinting case UserAdChoice.NotPrinting: AdOptionModel admodel = new AdOptionModel(); admodel = _adoption.GetSpecialDetail(((byte)SpecialAddOptions.NotPrinting).ToString()); list[i].AdOptionID = admodel.ADOptionID; list[i].ADOptionName = admodel.ADOptionName; list[i].NotPrinting = true; item.NotPrinting = true; break; #endregion #region Doing Own Distribution (Creating Own Artwork) case UserAdChoice.DoingOwnDistribution: AdOptionModel adselfmodel = new AdOptionModel(); adselfmodel = _adoption.GetSpecialDetail(((byte)SpecialAddOptions.SelfDistributing).ToString()); list[i].AdOptionID = adselfmodel.ADOptionID; list[i].ADOptionName = adselfmodel.ADOptionName; list[i].OwnDistribution = true; item.OwnDistribution = true; break; #endregion #region if Not selected case UserAdChoice.None: counter++; msg += utilityHelper.ReadGlobalMessage("StoreAdChoice", "None").Replace("[Store]", item.StoreID.ToString()) + "<br>"; break; #endregion } i++; } #endregion if (counter > 0) { TransMessage.Status = MessageStatus.Error; TransMessage.Message = msg; } else { SessionHelper.SessionForModel = list; TransMessage.Status = MessageStatus.Success; TransMessage.Message = utilityHelper.ReadGlobalMessage("StoreAdChoice", "RedirectToConfirmation"); } } } catch (Exception ex) { } return(Json(TransMessage, JsonRequestBehavior.DenyGet)); }