コード例 #1
0
        private async Task <OfferFormViewModels> ViewCreate()
        {
            var people = await _peopleService.FindAllAsync();

            var product = await _productService.FindAllAsync();

            var viewModel = new OfferFormViewModels {
                Peoples = people, Products = product
            };

            return(viewModel);
        }
コード例 #2
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 }));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Create()
        {
            try
            {
                var people = await _peopleService.FindAllAsync();

                var product = await _productService.FindAllAsync();

                var viewModel = new OfferFormViewModels {
                    Peoples = people, Products = product
                };
                return(View(viewModel));
            }
            catch (Exception e)
            {
                return(RedirectToAction(nameof(Error), new { message = e.Message }));
            }
        }