Example #1
0
 public IActionResult Delete(int id)
 {
     if (ticketsService.Contains(id))
     {
         ticketsService.Delete(id);
         return(NoContent());
     }
     else
     {
         return(NotFound($"Unable to find ticket with id {id}"));
     }
 }
 public ActionResult <Boolean> Delete(int id)
 {
     try
     {
         string nameIdentifier = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         if (nameIdentifier != null)
         {
             return(Ok(_ticketsService.Delete(id, nameIdentifier)));
         }
         else
         {
             throw new UnauthorizedAccessException("Unauthorized");
         }
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Example #3
0
        public virtual ActionResult Edit(TicketViewModel ticket)
        {
            if (ticket.TicketId == 0)
            {
                DateTime?assignedToDate = null;
                var      types          = TicketsService.GetTypes();
                var      ticketCategory = types.Where(x => x.Id == ticket.TicketTypeId).Single().TicketCategory;

                switch (ticketCategory)
                {
                case TicketTypeEnum.Daily:
                    assignedToDate = DateTime.Now.AddDays(1);
                    break;

                case TicketTypeEnum.Weekly:
                    assignedToDate = DateTime.Now.AddDays(7);
                    break;

                case TicketTypeEnum.Monthly:
                    assignedToDate = DateTime.Now.AddMonths(1);
                    break;
                }
                if (assignedToDate != null)
                {
                    var ticketModel = new Ticket
                    {
                        ApplicationUserId = ticket.UserId,
                        AssignTime        = DateTime.Now,
                        TicketTypeId      = ticket.TicketTypeId,
                        AssignTo          = assignedToDate.Value
                    };
                    TicketsService.CreateTicket(ticketModel, ticketModel.ApplicationUserId);
                    return(RedirectToAction(MVC.Users.Index()));
                }
            }
            else
            {
                TicketsService.Delete(ticket.TicketId, ticket.UserId);
            }
            return(RedirectToAction(MVC.Users.Index()));
        }