示例#1
0
        public async Task <OfferModel> Add(UpsertOfferModel model)
        {
            var offer = _mapper.Map <Offer>(model);

            await _repository.Add(offer);

            await _repository.SaveChanges();

            return(_mapper.Map <OfferModel>(offer));
        }
        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);
        }
示例#3
0
        public async Task <Offer> Add(Offer product)
        {
            var result = _offerRepository.Add(product);

            return(result);
        }