public async Task <SpecialOffer> AddSpecialOffer(AddSpecialOfferParameters specialOffer)
        {
            var temp = await context.Enterprises.Include(i => i.SpecialOffers).FirstOrDefaultAsync(i => i.Id == specialOffer.EnterpriseId);

            var tempSpecialOffer = new SpecialOffer();

            tempSpecialOffer.Name         = specialOffer.Name;
            tempSpecialOffer.Description  = specialOffer.Description;
            tempSpecialOffer.Discount     = Int32.Parse(specialOffer.Discount);
            tempSpecialOffer.NumberOfDays = Int32.Parse(specialOffer.NumberOfDays);

            temp.SpecialOffers.Add(tempSpecialOffer);

            return(tempSpecialOffer);
        }
Exemple #2
0
        public async Task <SpecialOffer> AddSpecialOffer(AddSpecialOfferParameters specialOffer)
        {
            try
            {
                var temp = await repo.AddSpecialOffer(specialOffer);

                if (temp != null)
                {
                    await unitOfWork.CompleteAsync();
                }
                return(temp);
            }
            catch
            {
                return(null);
            }
        }
        public async Task <IActionResult> AddSpecialOffer(AddSpecialOfferParameters specialOffer)
        {
            if (ModelState.IsValid)
            {
                var temp = await specialOfferService.AddSpecialOffer(specialOffer);

                if (temp != null)
                {
                    return(Ok(temp));
                }
                else
                {
                    return(BadRequest(new { Message = "Something went wrong. Please, try again later." }));
                }
            }
            else
            {
                return(BadRequest(new { Message = "Invalid parameters supplied." }));
            }
        }