public IHttpActionResult PostWorkOrder(WorkOrdersModel workOrder) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbWorkOrder = new WorkOrder(workOrder); db.WorkOrders.Add(dbWorkOrder); db.SaveChanges(); workOrder.WorkOrderId = dbWorkOrder.WorkOrderId; return CreatedAtRoute("DefaultApi", new { id = workOrder.WorkOrderId }, workOrder); }
public void Update(WorkOrdersModel w) { PropertyId = w.PropertyId; TenantId = w.TenantId; Description = w.Description; OpenedDate = w.OpenedDate; ClosedDate = w.ClosedDate; Priority = (Priorities)w.Priority; }
public WorkOrder(WorkOrdersModel workOrder) { this.Update(workOrder); }
public IHttpActionResult PutWorkOrder(int id, WorkOrdersModel workOrder) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != workOrder.WorkOrderId) { return BadRequest(); } // var dbWorkOrders = db.WorkOrders.Find(id); var dbWorkOrders = db.WorkOrders.FirstOrDefault(p => p.Property.User.UserName == User.Identity.Name && p.WorkOrderId == id); if (dbWorkOrders == null) { return BadRequest(); } dbWorkOrders.Update(workOrder); db.Entry(dbWorkOrders).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!WorkOrderExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }