Ejemplo n.º 1
0
        public async Task <IActionResult> AddTicket(TicketToCreateDto ticketToCreate)
        {
            if (ticketToCreate.userId != null)
            {
                var userFromRepo = await _repo.GetUser(ticketToCreate.userId, false);

                if (userFromRepo == null)
                {
                    return(BadRequest());
                }
                if (userFromRepo.project.Id != ticketToCreate.projectId)
                {
                    return(BadRequest());
                }
            }


            var newTicket = _mapper.Map <Ticket>(ticketToCreate);

            newTicket.project = await _repo.GetProject(ticketToCreate.projectId);

            if (ticketToCreate.userId != null)
            {
                newTicket.User = await _repo.GetUser(ticketToCreate.userId, false);
            }
            if (ticketToCreate.CategoryId != 0)
            {
                newTicket.Status = await _repo.GetStatus(ticketToCreate.CategoryId);
            }
            if (ticketToCreate.StatusId != 0)
            {
                newTicket.Category = await _repo.GetCategory(ticketToCreate.CategoryId);
            }
            if (ticketToCreate.PriorityId != 0)
            {
                newTicket.Priority = await _repo.GetPriority(ticketToCreate.PriorityId);
            }

            _repo.Add(newTicket);

            if (await _repo.SaveAll())
            {
                var ticketToReturn = _mapper.Map <TicketsForDetailed>(newTicket);
                return(Ok(ticketToReturn));
            }

            throw new Exception("Ticket can't created");
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> RemoveStatus(int id)
        {
            var statusFromRepo = await _repo.GetStatus(id);

            _repo.Delete(statusFromRepo);
            if (await _repo.SaveAll())
            {
                return(NoContent());
            }
            throw new Exception("Delete fail");
        }