public IActionResult Edit([FromBody] CreateProductOfferInputModel input, int id)
        {
            var offer = _offersService.GetById(id);

            if (offer == null)
            {
                return(NotFound());
            }

            return(Ok());
        }
        public CreateProductOfferOutputModel Create(CreateProductOfferInputModel input)
        {
            string currentUserId = ((ClaimsIdentity)User.Identity)
                                   .Claims
                                   .FirstOrDefault(c => c.Type == "sub")
                                   ?.Value;

            var offerId = _offersService.Create(input, currentUserId);

            return(new CreateProductOfferOutputModel {
                OfferId = offerId
            });
        }
        public int Create(CreateProductOfferInputModel input, string currentUserId)
        {
            if (_offersRepository.ExistsByName(input.Name))
            {
                throw new ArgumentException("Offer with this name exists");
            }

            IEnumerable <Product> selectedProducts = _productsRepository.GetByIds(input.Products);

            Offer offer = new Offer
            {
                Name       = input.Name,
                TotalPrice = decimal.Round(input.TotalPrice),
                Discount   = input.Discount,
                ExpiryDate = DateTime.ParseExact(input.ExpiryDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture),
                Image      = input.ImageUrl,
                AddedById  = currentUserId,
                IsActive   = input.IsActive
            };

            _offersRepository.Add(offer);
            _offersRepository.SaveChanges();

            foreach (var selectedProduct in selectedProducts)
            {
                ProductOffer po = new ProductOffer
                {
                    OfferId   = offer.Id,
                    ProductId = selectedProduct.Id
                };

                _productOffersRepository.Add(po);
                _productOffersRepository.SaveChanges();
            }

            return(offer.Id);
        }