Ejemplo n.º 1
0
        public HttpResponseMessage Create(HttpRequestMessage request, InitiativeViewModel initiativeVM)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                if (!ModelState.IsValid)
                {
                    response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var initiative = Mapper.Map <InitiativeViewModel, Initiative>(initiativeVM);

                    var userId = User.Identity.GetUserId();

                    var res = _initiativeService.Add(initiative, userId);

                    response = res ? request.CreateResponse(HttpStatusCode.Created, new Initiative()) : request.CreateResponse(HttpStatusCode.BadRequest, new Initiative());
                }

                return response;
            }));
        }