コード例 #1
0
 public void Update(WorkOrderModel modelWorkOder)
 {
     PropertyId = modelWorkOder.PropertyId;
     TenantId = modelWorkOder.TenantId;            
     Description = modelWorkOder.Description;
     Priority = modelWorkOder.Priority;
     OpenedDate = modelWorkOder.OpenedDate;
     ClosedDate = modelWorkOder.ClosedDate;            
 }
コード例 #2
0
        public IHttpActionResult PostWorkOrder(WorkOrderModel workOrder)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var newWorkOrder = new WorkOrder();
            newWorkOrder.Update(workOrder);

            db.WorkOrders.Add(newWorkOrder);
            db.SaveChanges();

            workOrder.WorkOrderId = newWorkOrder.WorkOrderId;

            return CreatedAtRoute("DefaultApi", new { id = workOrder.WorkOrderId }, workOrder);
        }
コード例 #3
0
        public IHttpActionResult PutWorkOrder(int id, WorkOrderModel modelWorkOrder)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != modelWorkOrder.WorkOrderId)
            {
                return BadRequest();
            }

            // 1. Gran entry from database by ID
            var dbWorkOrder = db.WorkOrders.Find(id);
            // 2. Update fetched entry from the database
            dbWorkOrder.Update(modelWorkOrder);
            // 3. Mark entry as modified
            db.Entry(dbWorkOrder).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!WorkOrderExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }