public ActionResult PromotionCreate(PromotionCreateModel pcm) { this.AccountBase.SetupActionAccount(); // Because of the weird control, we fetch deals from a json param: string jsonDeal = Request.Form["Deals"]; // first try to serialize it as a single thing, then try as an array; dynamic deal = null; pcm.Deals = new List <Deal>(); try { deal = jsonDeal.GetJson(); Deal d = ConvertDynamicToDeal(deal); pcm.Deals.Add(d); } catch (Exception) { } if (deal == null) { jsonDeal = "[" + jsonDeal + "]"; deal = jsonDeal.GetJson(); if (deal != null) { foreach (dynamic foo in deal) { Deal d = ConvertDynamicToDeal(foo); pcm.Deals.Add(d); } } else { //error } } Promotion p = pcm.ToPromotion(); var userbusinesses = AccountBase.BusinessActions.GetBusinessForUser(AccountBase.Account); p.Business = userbusinesses != null && userbusinesses.Count() > 0 ? userbusinesses.First() : new Business(); this.AccountBase.PromotionActions.SavePromotion(p); return(View(pcm)); }
public ActionResult PromotionCreate(PromotionCreateModel pcm) { this.AccountBase.SetupActionAccount(); // Because of the weird control, we fetch deals from a json param: string jsonDeal = Request.Form["Deals"]; // first try to serialize it as a single thing, then try as an array; dynamic deal = null; pcm.Deals = new List<Deal>(); try { deal = jsonDeal.GetJson(); Deal d = ConvertDynamicToDeal(deal); pcm.Deals.Add(d); } catch(Exception) { } if (deal == null) { jsonDeal = "[" + jsonDeal + "]"; deal = jsonDeal.GetJson(); if (deal != null) { foreach (dynamic foo in deal) { Deal d = ConvertDynamicToDeal(foo); pcm.Deals.Add(d); } } else { //error } } Promotion p = pcm.ToPromotion(); var userbusinesses = AccountBase.BusinessActions.GetBusinessForUser(AccountBase.Account); p.Business = userbusinesses != null && userbusinesses.Count() > 0 ? userbusinesses.First() : new Business(); this.AccountBase.PromotionActions.SavePromotion(p); return View(pcm); }
public ActionResult Create(PromotionCreateModel promotion) { String[] stringList = new String[50]; try { if (ModelState.IsValid) { if (!String.IsNullOrEmpty(promotion.Tags)) { stringList = promotion.Tags.Split(','); } using (var unitOfWork = new UnitOfWork()) { var promId = unitOfWork.InsertPromotionDetailsByUsername(promotion.Price, promotion.Description, promotion.StartDate, promotion.EndDate, User.Identity.Name); if (promId.HasValue) { foreach (var s in stringList.ToList()) { if (!String.IsNullOrEmpty(s)) { var tag = s.Trim(); unitOfWork.InsertPromotionTag(promId, tag); } } } } } return(RedirectToAction("Index")); } catch (Exception ex) { return(View()); } }
// GET: Promotion/Create public ActionResult Create() { var promotion = new PromotionCreateModel(); return(View(promotion)); }
public ActionResult PromotionCreate() { PromotionCreateModel pcm = new PromotionCreateModel(); return(View(pcm)); }
public ActionResult PromotionCreate() { PromotionCreateModel pcm = new PromotionCreateModel(); return View(pcm); }