public HttpResponseMessage Create(AssignmentView view) { if (ModelState.IsValid) { try { var original = view.convert(this._context); original.created = DateTime.UtcNow; this._context.assignments.Add(original); this._context.SaveChanges(); view = new AssignmentView(original); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, view); //response.Headers.Location = new Uri(Url.Link("Default", new { id = performer.performerID })); return response; } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex); } } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
public HttpResponseMessage Update(AssignmentView view) { if (ModelState.IsValid) { try { var original = this._context.assignments.FirstOrDefault(a => a.id == view.id); original.updated = DateTime.UtcNow; AutoMapper.Mapper.CreateMap<Assignment, Assignment>(); AutoMapper.Mapper.Map<Assignment, Assignment>(view.convert(this._context), original); this._context.SaveChanges(); } catch (Exception ex) { return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex); } HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, view); //response.Headers.Location = new Uri(Url.Link("Default", new { id = performer.performerID })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }