コード例 #1
0
        //create
        public async Task <IActionResult> Create()
        {
            var model = new DiscountModel();
            await _discountViewModelService.PrepareDiscountModel(model, null);

            //Stores
            await model.PrepareStoresMappingModel(null, _storeService, false, _workContext.CurrentCustomer.StaffStoreId);

            //default values
            model.LimitationTimes = 1;
            return(View(model));
        }
コード例 #2
0
        public async Task <IActionResult> Edit(DiscountModel model, bool continueEditing)
        {
            var discount = await _discountService.GetDiscountById(model.Id);

            if (discount == null)
            {
                //No discount found with the specified id
                return(RedirectToAction("List"));
            }

            if (_workContext.CurrentCustomer.IsStaff())
            {
                if (!discount.AccessToEntityByStore(_workContext.CurrentCustomer.StaffStoreId))
                {
                    return(RedirectToAction("Edit", new { id = discount.Id }));
                }
            }

            if (ModelState.IsValid)
            {
                if (_workContext.CurrentCustomer.IsStaff())
                {
                    model.LimitedToStores  = true;
                    model.SelectedStoreIds = new string[] { _workContext.CurrentCustomer.StaffStoreId };
                }
                discount = await _discountViewModelService.UpdateDiscountModel(discount, model);

                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Discounts.Updated"));
                if (continueEditing)
                {
                    //selected tab
                    await SaveSelectedTabIndex();

                    return(RedirectToAction("Edit", new { id = discount.Id }));
                }
                return(RedirectToAction("List"));
            }
            //If we got this far, something failed, redisplay form
            await _discountViewModelService.PrepareDiscountModel(model, discount);

            //Stores
            await model.PrepareStoresMappingModel(discount, _storeService, true, _workContext.CurrentCustomer.StaffStoreId);

            return(View(model));
        }
コード例 #3
0
        public async Task <IActionResult> Create(DiscountModel model, bool continueEditing)
        {
            if (ModelState.IsValid)
            {
                if (_workContext.CurrentCustomer.IsStaff())
                {
                    model.LimitedToStores  = true;
                    model.SelectedStoreIds = new string[] { _workContext.CurrentCustomer.StaffStoreId };
                }

                var discount = await _discountViewModelService.InsertDiscountModel(model);

                SuccessNotification(_localizationService.GetResource("Admin.Promotions.Discounts.Added"));
                return(continueEditing ? RedirectToAction("Edit", new { id = discount.Id }) : RedirectToAction("List"));
            }
            //If we got this far, something failed, redisplay form
            await _discountViewModelService.PrepareDiscountModel(model, null);

            //Stores
            await model.PrepareStoresMappingModel(null, _storeService, true, _workContext.CurrentCustomer.StaffStoreId);

            return(View(model));
        }