public void saveChanges()
        {
            using (var db = new PlanningContext())
            {
                device_history data = null;

                if (!this._isCreateMode)
                {
                    var id = Convert.ToInt32(this.device_history_id.Text);
                    data = db.device_history.Where(d => d.device_history_id == id).FirstOrDefault();
                    if (data == null)
                    {
                        this._mainInterface.statusText = $"ERROR: ID '{this.device_history_id.Text}' does not exist.";
                        return;
                    }
                }
                else
                {
                    data = new device_history();
                }

                data.device_history_id = Convert.ToInt32(this.device_history_id.Text);
                data.datetime          = (DateTime)this.datetime.SelectedDate;
                data.is_active         = (bool)this.is_active.IsChecked;
                data.comment           = /**/ (this.comment.Text);
                data.device            = new Func <device>(() => { foreach (var v in db.devices)
                                                                   {
                                                                       if (v.device_id == (this.device.item as device).device_id)
                                                                       {
                                                                           return(v);
                                                                       }
                                                                   }
                                                                   return(null); })();
                data.device_history_action = new Func <device_history_action>(() => { foreach (var v in db.device_history_action)
                                                                                      {
                                                                                          if (v.device_history_action1 == (this.device_history_action.item as device_history_action).device_history_action1)
                                                                                          {
                                                                                              return(v);
                                                                                          }
                                                                                      }
                                                                                      return(null); })();
                data.supplier = new Func <supplier>(() => { foreach (var v in db.suppliers)
                                                            {
                                                                if (v.supplier_id == (this.supplier.item as supplier).supplier_id)
                                                                {
                                                                    return(v);
                                                                }
                                                            }
                                                            return(null); })();


                if (this._isCreateMode)
                {
                    db.device_history.Add(data);
                }
                db.SaveChanges();
            }
        }
        public async Task <ActionResult <device_history> > Postdevice_history(device_history device_history)
        {
            _context.device_histories.Add(device_history);
            await _context.SaveChangesAsync();

            return(new OkObjectResult(new
            {
                Success = true,
                Message = "Ok",
                Data = CreatedAtAction("Getdevice_history", new { id = device_history.device_history_id }, device_history)
            }));
        }
Esempio n. 3
0
        public void deleteItem(object item)
        {
            if (item == null)
            {
                return;
            }

            device_history data = item as device_history;

            if (data == null)
            {
                return;
            }

            using (var db = new PlanningContext())
            {
                db.device_history.Remove(db.device_history.Where(d => d.device_history_id == data.device_history_id).First());
                db.SaveChanges();
            }
        }
        public async Task <IActionResult> Putdevice_history(int id, device_history device_history)
        {
            if (id != device_history.device_history_id)
            {
                return(new OkObjectResult(new
                {
                    Success = false,
                    Message = "Ok",
                    Data = BadRequest()
                }));
            }

            _context.Entry(device_history).State = EntityState.Modified;

            try
            {
                return(new OkObjectResult(new
                {
                    Success = true,
                    Message = "Ok",
                    Data = _context.SaveChangesAsync()
                }));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!device_historyExists(id))
                {
                    return(new OkObjectResult(new
                    {
                        Success = false,
                        Message = "Ok",
                        Data = NotFound()
                    }));
                }
                else
                {
                    throw;
                }
            }
        }