Esempio n. 1
0
        public async Task <IActionResult> AddPromoItems(int id)
        {
            var category = await _promoCategoryRepository.GetAsync(id);

            var model = new CreatePromoItemsModel
            {
                PromoCategoryId   = id,
                PromoCategoryName = category.Name,
            };

            return(View(model));
        }
Esempio n. 2
0
        public async Task <IActionResult> AddPromoItems(CreatePromoItemsModel model)
        {
            if (ModelState.IsValid)
            {
                var category = await _promoCategoryRepository.GetAsync(model.PromoCategoryId);

                var lines = model.Codes.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                foreach (var code in lines)
                {
                    await _promoItemsRepository.AddAsync(new PromoItem
                    {
                        Category  = category,
                        Code      = code,
                        CreatedAt = DateTime.UtcNow,
                    });
                }
            }

            return(RedirectToAction("EditPromoItems", new { id = model.PromoCategoryId }));
        }