Exemplo n.º 1
0
        public WorkOrderBase WorkOrderAdd(WorkOrderAdd newItem)
        {
            if (newItem == null)
            {
                return(null);
            }

            var associatedTenant = ds.Tenants.Find(newItem.TenantId);

            if (associatedTenant == null)
            {
                return(null);
            }

            WorkOrder addedItem = Mapper.Map <WorkOrder>(newItem);

            var today = DateTime.Now;

            addedItem.Tenant      = associatedTenant;
            addedItem.RequestDate = today;

            ds.WorkOrders.Add(addedItem);
            ds.SaveChanges();

            return(Mapper.Map <WorkOrderBase>(addedItem));
        }
Exemplo n.º 2
0
        public IHttpActionResult Post([FromBody] WorkOrderAdd newItem)
        {
            if (Request.GetRouteData().Values["id"] != null)
            {
                return(BadRequest("Invalid request URI"));
            }

            if (newItem == null)
            {
                return(BadRequest("Must send an entity body with the request"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var addedItem = m.WorkOrderAdd(newItem);

            if (addedItem == null)
            {
                return(BadRequest("Cannot add the object"));
            }

            // HTTP 201
            var uri = Url.Link("DefaultApi", new { id = addedItem.Id });

            return(Created(uri, addedItem));
        }