public ActionResult Post([FromBody] ViewModel.Api.WorkOrder viewmodel) { MapperHelpers.ClientTimeZoneInfo = _clientTimeZoneInfo; var workOrder = map.Map <ViewModel.Api.WorkOrder, Domain.WorkOrder>(viewmodel); workOrder.Employer = Employer; workOrder.EmployerID = Employer.ID; workOrder.onlineSource = true; Domain.WorkOrder newOrder; try { newOrder = serv.Create(workOrder, Employer.email ?? Employer.name); } catch (MacheteValidationException e) { var res = new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new StringContent(e.ErrorMessage), ReasonPhrase = "Validation failed on workOrder" }; return(BadRequest(res)); } catch (InvalidOperationException e) { var res = new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(e.Message), ReasonPhrase = "Invalid operation " }; return(BadRequest(res)); } ViewModel.Api.WorkOrder result = map.Map <Domain.WorkOrder, ViewModel.Api.WorkOrder>(newOrder); return(new JsonResult(new { data = result })); }
public void Put(int id, [FromBody] ViewModel.Api.WorkOrder order) { var domain = _serv.Get(order.id); // TODO employers must only be able to edit their record _map.Map <ViewModel.Api.WorkOrder, Domain.WorkOrder>(order, domain); _serv.Save(domain, UserEmail); }
public ActionResult Get(int orderID) { Domain.WorkOrder order = null; try { order = serv.Get(orderID); if (order.EmployerID != Employer.ID) { throwInvalidOrder(orderID); } } catch { throwInvalidOrder(orderID); } // TODO: Not mapping to view object throws JsonSerializationException, good to test error // handling with...(delay in error) ViewModel.Api.WorkOrder result = map.Map <Domain.WorkOrder, ViewModel.Api.WorkOrder>(order); return(new JsonResult(new { data = result })); }
public void Post([FromBody] ViewModel.Api.WorkOrder order) { var domain = _map.Map <ViewModel.Api.WorkOrder, Domain.WorkOrder>(order); _serv.Save(domain, UserEmail); }