コード例 #1
0
        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 }));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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 }));
        }
コード例 #4
0
        public void Post([FromBody] ViewModel.Api.WorkOrder order)
        {
            var domain = _map.Map <ViewModel.Api.WorkOrder, Domain.WorkOrder>(order);

            _serv.Save(domain, UserEmail);
        }