Exemple #1
0
        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));
        }
Exemple #3
0
 public IActionResult UpdateAssignee(int id)
 {
     return(View("Edit", assigneeRepository.GetAssignee(id)));
 }