public async Task <IActionResult> AddAssignment([FromBody] DeviceAssignmentSaveResource saveResource) { if (!_auth.IsValidUser(User)) { return(NoContent()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (await _deviceRepo.GetDevice(saveResource.DeviceId) == null) { return(BadRequest($"Device {saveResource.DeviceId} could not be found.")); } if (await _assigneeRepo.GetAssignee(saveResource.AssigneeId) == null) { return(BadRequest($"Assignee {saveResource.AssigneeId} could not be found.")); } var filter = new MdaAssignmentQuery() { DeviceId = saveResource.DeviceId, AssignmentType = saveResource.AssignmentType, AssigneeId = saveResource.AssigneeId }; var assigmentFromRepo = await _repo.GetAssignments(filter); if (assigmentFromRepo.Any()) { return(BadRequest($"Assignment already exists.")); } var assignment = _mapper.Map <MdaDeviceAssignment>(saveResource); assignment.CreatedBy = User.Identity.Name; if (saveResource.StartDate == DateTime.MinValue) { assignment.StartDate = DateTime.Now; } _repo.Add(assignment); if (await _repo.SaveAll()) { return(Ok(assignment)); } return(BadRequest("Failed to add assignment")); }
public async Task <IActionResult> GetAssignee(int id) { if (!_auth.IsValidUser(User)) { return(NoContent()); } var assignee = await _repo.GetAssignee(id); var assigneeItem = _mapper.Map <AssigneeForList>(assignee); return(Ok(assigneeItem)); }
public IActionResult UpdateAssignee(int id) { return(View("Edit", assigneeRepository.GetAssignee(id))); }