コード例 #1
0
 public async Task<bool> Create(Device device)
 {
     _db.Devices.Add(device);
     await Save();
     return true;
 }
コード例 #2
0
 public async Task<bool> Edit(Device device)
 {
     _db.Entry(device).State = EntityState.Modified;
     await Save();
     return true;
 }
コード例 #3
0
 public async Task<IHttpActionResult> Create(CreateDeviceBindingModel model)
 {
     if (model != null)
     {
         var device = new Device { Name = model.Name, Manufacturer = model.Manufacturer, Year = model.Year, Image = model.Image };
         if (model.RecoveryIds != null)
         {
             foreach (int recoveryId in model.RecoveryIds)
             {
                 Recovery temp = await _repo2.Get(recoveryId);
                 if (temp != null)
                 {
                     device.Recoveries.Add(temp);
                 }
             }
         }
         if (await _repo.Create(device))
         {
             return Ok();
         }
     }
     return BadRequest("Model error.");
 }