Exemplo n.º 1
0
 public IHttpActionResult Create([FromBody] MaterialRequestModel model)
 {
     try
     {
         var materialRequest = new MaterialRequest();
         Mapper.Map(model, materialRequest);
         var user = GetCurrentUser();
         materialRequest.SubmittedBy = user.Id;
         _materialRequestsService.Create(materialRequest);
         model.Id       = materialRequest.Id;
         model.StatusId = model.StatusId;
         return(Ok(model));
     }
     catch (DbEntityValidationException ex)
     {
         foreach (var entityValidationErrors in ex.EntityValidationErrors)
         {
             foreach (var validationError in entityValidationErrors.ValidationErrors)
             {
                 model.SetError(validationError.PropertyName, validationError.ErrorMessage);
             }
         }
         return(Ok(model));
     }
     catch (Exception)
     {
         return(InternalServerError());
     }
 }
Exemplo n.º 2
0
        public IHttpActionResult Update([FromUri] int id, [FromBody] MaterialRequestModel model)
        {
            try
            {
                var materialRequest = _materialRequestsService.GetMaterialRequest(id);
                if (materialRequest == null)
                {
                    return(NotFound());
                }

                //update the MaterialRequests DAO items with the MaterialRequests DTO items
                materialRequest.RequestedStrands.Clear();
                materialRequest.RequestedDuplexes.Clear();
                Mapper.Map(model, materialRequest);
                if (_materialRequestsService.IsStatusExists(model.Status.Id))
                {
                    materialRequest.StatusId = model.Status.Id;
                }

                _materialRequestsService.Update(materialRequest);
                model.Id       = materialRequest.Id;
                model.StatusId = materialRequest.StatusId;
                return(Ok(model));
            }
            catch (DbEntityValidationException ex)
            {
                foreach (var entityValidationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in entityValidationErrors.ValidationErrors)
                    {
                        model.SetError(validationError.PropertyName, validationError.ErrorMessage);
                    }
                }
                return(Ok(model));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }