public IActionResult Create(CreateSupplierModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(model));
            }

            this.supplierService.Create(model.Name, model.IsImporter);

            this.logService.Create(User.Identity.Name, "Create", "Supplier");

            return(RedirectToAction(nameof(AllSuppliers)));
        }
Example #2
0
        public async Task <IActionResult> CreateSupplier([FromBody] CreateSupplierModel s, CancellationToken cancellationToken)
        {
            try
            {
                var supplierId = await _mediator.Send(new CreateSupplierRequest
                {
                    Name = s?.Name
                });

                return(CreatedAtAction("CreateSupplier", supplierId));
            }
            catch (SupplierNotCreateException ex)
            {
                _logger.LogError(ex, "Failed to create supplier");
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex, "Failed to create supplier");
                return(BadRequest());
            }
        }
 public async Task <ActionResult <object> > CreateAsync([FromBody] CreateSupplierModel model)
 {
     return(await _supplier.CreateAsync(model));
 }