コード例 #1
0
        public async Task <IActionResult> EditPromotion([FromBody] PromotionDTO model)
        {
            var email = (await _userManager.GetUserAsync(HttpContext.User)).Email;
            var user  = await _userRepository.FindByEmail(email);

            var business = user.Business;

            if (business == null)
            {
                return(Unauthorized());
            }

            if (business.Promotions == null)
            {
                new Exception("Promotielijst is leeg, er kan niets worden aangepast.");
            }

            var editPromotion = await _promotionRepository.FindById(model.Id);

            editPromotion.Name          = model.Name;
            editPromotion.Description   = model.Description;
            editPromotion.PromotionType = model.PromotionType;
            editPromotion.EndDate       = model.EndDate;
            editPromotion.StartDate     = model.StartDate;

            await _promotionRepository.SaveChanges();

            return(Ok());
        }