public IHttpActionResult PutWorkOrder(int id, WorkOrderModel workOrder)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

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

            var dbWorkOrder = db.WorkOrders.Find(id);

            dbWorkOrder.Update(workOrder);
            db.Entry(dbWorkOrder).State = EntityState.Modified;

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

            return StatusCode(HttpStatusCode.NoContent);
        }
Пример #2
0
 public void Update(WorkOrderModel model)
 {
     WorkOrderId = model.WorkOrderId;
     PropertyId = model.PropertyId;
     UserId = model.UserId;
     TenantId = model.TenantId;
     Descriptions = model.Descriptions;
     OpenDate = model.OpenDate;
     ClosedDate = model.ClosedDate;
     Priority = model.Priority;
 }
        public IHttpActionResult PostWorkOrder(WorkOrderModel workOrder)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var dbWorkOrder = new WorkOrder(workOrder);
            dbWorkOrder.User = db.Users.FirstOrDefault(u => u.UserName == User.Identity.Name);

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


            workOrder.WorkOrderId = dbWorkOrder.WorkOrderId;

            return CreatedAtRoute("DefaultApi", new { id = workOrder.WorkOrderId }, workOrder);
        }
Пример #4
0
 public WorkOrder(WorkOrderModel model)
 {
     this.Update(model);
 }