// POST api/<controller>
        public HttpResponseMessage Post([FromBody] ViewModels.Component component)
        {
            try
            {
                component.Id = _componentService.Add(component);

                return(Request.CreateResponse(HttpStatusCode.OK, component));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
            }
        }
Exemplo n.º 2
0
 public ActionResult Add([Bind(Include = "Code,Description,UnitsOfMeasure,QtyOnHand")] ComponentDetailVM componentVM)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _componentService.Add(componentVM);
             return(Json(new { success = true, model = componentVM }));
         }
         catch (Exception ex)
         {
             if (ex.Message.Contains("IX_Code"))
             {
                 ModelState.AddModelError("Code", "This Component Number already exists. Duplicate Component Numbers are not allowed.");
             }
             else
             {
                 ModelState.AddModelError(string.Empty, "The save failed.");
             }
         }
     }
     return(JsonErrorResult());
 }
        public async Task <ActionResult> Post([FromBody] AddComponentCommand command)
        {
            var result = await _componentService.Add(command);

            return(Ok(result));
        }