コード例 #1
0
        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);
        }
コード例 #2
0
 public void Update(WorkOrdersModel w)
 {
     PropertyId = w.PropertyId;
     TenantId = w.TenantId;
     Description = w.Description;
     OpenedDate = w.OpenedDate;
     ClosedDate = w.ClosedDate;
     Priority = (Priorities)w.Priority;
 }
コード例 #3
0
 public WorkOrder(WorkOrdersModel workOrder)
 {
     this.Update(workOrder);
 }
コード例 #4
0
        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);
        }