public IHttpActionResult Post(Guid companyId, DeviceInputModel model) { var device = DeviceRepository.GetByMacAddress(MacAddress.From(model.MacAddress)); if (device == null) { device = Device.CreateNew(companyId, MacAddress.From(model.MacAddress), model.Comment); DeviceRepository.Add(device); var response = DeviceModel.From(device); return Created(new Uri(Url.Link("GetDevice", new { macAddress = device.MacAddress.ToString() })), response); } else if (device != null) { device.Comment = model.Comment; if (device.State == DeviceState.Declined) { return BadRequest("Device is declined"); } else if (device.State == DeviceState.Blocked) { return BadRequest("Device is blocked"); } } return BadRequest("Internal error"); }
public IHttpActionResult PostBlocked(Guid companyId, DeviceInputModel model) { var device = DeviceRepository.GetByMacAddress(MacAddress.From(model.MacAddress)); if (device == null || device.CompanyId != companyId) { return NotFound(); } device.Comment = model.Comment; if (device.State == DeviceState.Approved) { return BadRequest("Cannot block an already approved device."); } device.Block(); DeviceRepository.Update(device); return Created(new Uri(Url.Link("GetDevice", new { macAddress = device.MacAddress.ToString() })), DeviceModel.From(device)); }