public IActionResult PostDeviceType([FromBody] DeviceTypeViewModel vmdl) { try { var dt = _bl.CreateDeviceType(); vmdl.ApplyChanges(dt, _bl); _bl.SaveChanges(); _log.LogInformation("DeviceType '{0}' created by '{1}'", vmdl.Name, User.Identity.Name); vmdl.Refresh(dt); return(Ok(vmdl)); } catch (SecurityException) { _log.LogWarning("Security: '{0}' tried to create DeviceType '{1}'", _bl.GetCurrentUid(), vmdl.Name); return(Unauthorized()); } catch (Exception ex) { _log.LogError("Exception: '{0}'", ex); return(StatusCode(500)); } }
public IActionResult PutDeviceType(string slug, [FromBody] DeviceTypeViewModel vmdl) { try { var dt = _bl.GetDeviceType(slug); _bl.UpdateDeviceType(dt); vmdl.ApplyChanges(dt, _bl); _bl.SaveChanges(); _log.LogInformation("DeviceType '{0}' updated by '{1}'", vmdl.Name, User.Identity.Name); vmdl.Refresh(dt); return(Ok(vmdl)); } catch (DbUpdateConcurrencyException) { if (_bl.GetDeviceType(slug) == null) { _log.LogWarning("Not Found: DeviceType '{0}' not found", slug); return(NotFound()); } else { throw; } } catch (SecurityException) { _log.LogWarning("Security: '{0}' tried to update DeviceType '{1}'", _bl.GetCurrentUid(), slug); return(Unauthorized()); } catch (Exception ex) { _log.LogError("Exception: {0}", ex); return(StatusCode(500)); } }