Exemple #1
0
        public HttpResponseMessage PutForm(int id, [FromBody] PutFormDTO updated)
        {
            string userId = ((ClaimsPrincipal)RequestContext.Principal).FindFirst(x => x.Type == "UserId").Value;

            logger.Info("UserId: " + userId + ": Requesting Update for Form Id: " + id);

            if (updated.Id != id)
            {
                logger.Error("Updated Form id " + updated.Id + " doesn't match the id " + id + " from the request (route).");
                return(Request.CreateResponse(HttpStatusCode.BadRequest, "Updated " +
                                              "Form id " + updated.Id + " doesn't match the id " + id + " from the request (route)."));
            }

            try
            {
                FormDTOForAdmin saved = formsService.Update(id, updated);

                if (saved == null)
                {
                    logger.Info("Failed!");
                    return(Request.CreateResponse(HttpStatusCode.BadRequest, "Failed! Something went wrong."));
                }

                logger.Info("Success!");
                return(Request.CreateResponse(HttpStatusCode.OK, saved));
            }
            catch (Exception e)
            {
                logger.Error(e);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, e));
            }
        }