public async Task <ActionResult> CreateAssignees(AssigneeDTO assigneeDTO, int id)
        {
            Assignee assignee = _mapper.Map <AssigneeDTO, Assignee>(assigneeDTO);
            User     user     = _context.Users.Find(id);

            assignee.Creator   = user;
            assignee.CreatorId = user.Id;
            List <Assignee> assignees = _context.Assignees
                                        .Where(a => a.CreatorId == user.Id)
                                        .Where(a => a.Name == assigneeDTO.Name)
                                        .ToList();

            if (assignees.Count == 0)
            {
                _context.Add(assignee);
                await _context.SaveChangesAsync();

                return(new OkResult());
            }
            return(new BadRequestResult());
        }
Example #2
0
 public async Task <ActionResult <Assignee> > CreateAssignee([FromBody] AssigneeDTO assigneeDTO)
 {
     return(await assigneeService.CreateAssignees(assigneeDTO, Convert.ToInt32(User.Identity.Name)));
 }