Exemple #1
0
        public IActionResult AddCoupon(StoreCouponViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (_store.ExistsCouponCode(viewModel.Code))
                {
                    return(View(viewModel));
                }
                else
                {
                    string username = User.Identity.Name;

                    Store store = _user.GetUserStore(username);

                    Coupon coupon = new Coupon()
                    {
                        Code      = viewModel.Code,
                        Desc      = viewModel.Desc,
                        EndDate   = viewModel.EndDate,
                        IsExpire  = false,
                        StoreId   = store.UserId,
                        Name      = viewModel.Name,
                        Percent   = viewModel.Percent,
                        Price     = viewModel.Price,
                        StartDate = viewModel.StartDate
                    };

                    _store.AddCoupon(coupon);

                    return(RedirectToAction(nameof(ShowCoupons)));
                }
            }

            return(View(viewModel));
        }