Exemple #1
0
        public async Task <IActionResult> Create(Offer offer)
        {
            try
            {
                OfferFormViewModels result = null;

                if (!ModelState.IsValid)
                {
                    result = await ViewCreate();

                    return(View(result));
                }
                //

                Product prod = await _productService.FindByIdAsync(offer.ProductId);

                if (prod.CheckValue(offer.Value) == true)
                {
                    decimal value = await _offerService.FindBigValueByProductIdAsync(offer.ProductId);

                    if (value < offer.Value)
                    {
                        await _offerService.InsertAsync(offer);

                        return(RedirectToAction(nameof(Index)));
                    }
                    else
                    {
                        ViewBag.Message = ("It was not possible to offer, below value.");
                        result          = await ViewCreate();

                        return(View(result));
                    }
                }

                ViewBag.Message = ("It was not possible to offer, below value.");
                result          = await ViewCreate();

                return(View(result));
            }
            catch (Exception e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }