Ejemplo n.º 1
0
        public async Task <ServiceResult <ProductRequestViewModel> > GetSingle(int id)
        {
            var model = await _repository.GetSingleAsync(id);

            if (model == null)
            {
                return(ServiceResultFactory.Success <ProductRequestViewModel>(null));
            }

            var viewModel = new ProductRequestViewModel
            {
                ProductName       = model.Name,
                Code              = model.Code,
                EanCode           = model.EanCode,
                ProductGroupId    = model.ProductCategoryId,
                Description       = model.Description,
                SellingPriceBruto = model.Price,
                VatPercent        = model.Vat,
                Type              = model.ProductType,
                Unit              = model.Unit,
                UseProductVat     = model.UseProductVat
            };

            return(ServiceResultFactory.Success(viewModel));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> EditProduct(ProductRequestViewModel model)
        {
            try
            {
                bool response = await this._productService.UpdateProduct(model);

                if (response)
                {
                    return(RedirectToAction("Index"));
                }
                return(View());
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
        public ActionResult <string> Post(ProductRequestViewModel product)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(product));
                }

                _logger.LogInformation("Insert a new product", product);
                var result = _productServices.Insert(_mapper.Map <Product>(product));
                if (result.ValidationResult.Errors.Any())
                {
                    return(AddErrors(result.ValidationResult.Errors));
                }

                return(Ok("product inserted"));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                return(new StatusCodeResult(500));
            }
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Detail(ProductRequestViewModel requestViewModel)
        {
            if (ModelState.IsValid)
            {
                if (await this.captcha.IsValid(requestViewModel.Request.CaptchaToken, HttpContext.Connection.RemoteIpAddress?.ToString()))
                {
                    var command = requestViewModel.ToCommand(this.enginexEmail.Value.Email, Request.GetDisplayUrl());
                    await Mediator.Send(command);

                    ConfirmationMessage(this.localizer["RequestSent"]);
                    this.logger.Information($"Product request from '{requestViewModel.Request.Email}' has been sent.");
                    return(RedirectToAction(nameof(Detail), requestViewModel.Product.Id));
                }
                else
                {
                    this.logger.Error("Failed due to invalid CAPTCHA.");
                    ErrorMessage(this.localizer["InvalidCaptcha"]);
                }
            }

            requestViewModel.Product = await Mediator.Send(new GetProductQuery(requestViewModel.Request.ProductId));

            return(View(requestViewModel));
        }
        public ProductRequestPage()
        {
            InitializeComponent();

            BindingContext = _productRequestViewModel = new ProductRequestViewModel();
        }