public HttpResponseMessage Create(PerformerTimeReportView view) { if (ModelState.IsValid) { try { var original = view.convert(this._context); original.created = DateTime.UtcNow; this._context.performerTimeReports.Add(original); this._context.SaveChanges(); view = new PerformerTimeReportView(original); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, 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(PerformerTimeReportView view) { if (ModelState.IsValid) { try { var original = this._context.performerTimeReports.FirstOrDefault(a => a.id == view.id); original.updated = DateTime.UtcNow; AutoMapper.Mapper.CreateMap <PerformerTimeReport, PerformerTimeReport>(); AutoMapper.Mapper.Map <PerformerTimeReport, PerformerTimeReport>(view.convert(this._context), original); this._context.SaveChanges(); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex)); } return(Request.CreateResponse(HttpStatusCode.OK)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }