예제 #1
0
        public void AddPromotion(AddPromotionBindingModel bindingModel)
        {
            Category category = this.Context.Categories
                                .First(c => c.Id.ToString() == bindingModel.Categories);

            bindingModel.Categories = null;

            var newPromotion = Mapper.Map <AddPromotionBindingModel, Promotion>(bindingModel);

            newPromotion.Categories.Add(category);

            this.Context.Promotions.Add(newPromotion);
            this.Context.SaveChanges();
        }
        public ActionResult AddPromotion([Bind(Include = "Id,Name,Text,StartDate,EndDate,Discount,Categories")] AddPromotionBindingModel bindingModel)
        {
            if (bindingModel.Discount < 1 || bindingModel.Discount > 100)
            {
                return(this.View(bindingModel));
            }

            if (ModelState.IsValid)
            {
                this.promotionService.AddPromotion(bindingModel);
                var newPromotion = this.promotionService.GetPromotionByName(bindingModel.Name);

                return(RedirectToAction("Details", "Promotions", new { id = newPromotion.Id }));
            }

            return(View(bindingModel));
        }