public async Task <IActionResult> Post([FromBody] FormDto form)
        {
            try
            {
                VerifyUser();
                _validateService.Validate(form);
                var result = await _service.Create(form);

                return(Created(HttpContext.Request.Path, result));
            }
            catch (ServiceValidationException ex)
            {
                var Result = new
                {
                    error      = ResultFormatter.Fail(ex),
                    apiVersion = "1.0.0",
                    statusCode = HttpStatusCode.BadRequest,
                    message    = "Data does not pass validation"
                };

                return(new BadRequestObjectResult(Result));
            }
            catch (Exception ex)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, ex.Message));
            }
        }
Exemple #2
0
        public ActionResult Create(UOM uom)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (UOMService.FindBy(p => p.UOMName.Trim() == uom.UOMName.Trim()).Count() > 0)
                    {
                        ModelState.AddModelError("", "UOM alreary exists with same name");
                        return(View());
                    }

                    bool isModelValid = true;
                    if (!uom.ISStandardUOM)
                    {
                        if (string.IsNullOrEmpty(uom.StandardUOM))
                        {
                            ModelState.AddModelError("", "Please Select Standard UOM");
                            isModelValid = false;
                        }
                        else if (uom.UOMMapping == 0)
                        {
                            ModelState.AddModelError("", "Please enter mapping Details");
                            isModelValid = false;
                        }
                    }
                    if (isModelValid)
                    {
                        UOMService.Create(uom);
                    }
                }
            }
            catch { }

            return(View());
        }