public async Task <IActionResult> AssignUser(List <EditUsersInRoleViewModel> model, int id)
        {
            try
            {
                var ticket = dbContext.Tickets.Where(t => t.Id == id).Include(t => t.TicketApplicationUsers).SingleOrDefault();
                if (ticket == null)
                {
                    return(NotFound("No ticket ID provided. This might be bad."));
                }
                for (int i = 0; i < model.Count; i++)
                {
                    var user = await userManager.FindByIdAsync(model[i].UserId);

                    if (user == null)
                    {
                        return(NotFound("No user ID provided. This might be bad."));
                    }

                    if (model[i].IsSelected && !ticket.TicketApplicationUsers.Any(tau => tau.ApplicationUser == user))
                    {
                        TicketApplicationUser tau = new TicketApplicationUser();

                        tau.ApplicationUser = user;
                        tau.Ticket          = ticket;

                        ticket.TicketApplicationUsers.Add(tau);
                        dbContext.Tickets.Update(ticket);
                        //maybe better to put it before return, im too tired and afraid at this point to optimize
                        dbContext.SaveChanges();
                    }
                    else if (!model[i].IsSelected && ticket.TicketApplicationUsers.Any(tau => tau.ApplicationUser == user))
                    {
                        //not even going in here
                        var found = ticket.TicketApplicationUsers.FirstOrDefault(x => x.ApplicationUser == user);
                        if (found != null)
                        {
                            ticket.TicketApplicationUsers.Remove(found);
                        }
                        dbContext.Tickets.Update(ticket);
                        //maybe better to put it before return, im too tired and afraid at this point to optimize
                        dbContext.SaveChanges();
                    }
                    else
                    {
                        continue;
                    }
                }

                return(RedirectToAction("Details", new { id = id }));
            }
            catch (Exception e)
            {
                return(Json(new { e.Message }));
            }
        }
        public async Task <IActionResult> Create(CreateTicketViewModel model)
        {
            if (ModelState.IsValid)
            {
                Ticket ticket = new Ticket();
                ticket.Title       = model.Title;
                ticket.Description = model.Description;
                if (model.Description == null)
                {
                    ticket.Description = "No Description";
                }
                var user = await userManager.GetUserAsync(HttpContext.User);

                ticket.ApplicationUser = user;
                TicketApplicationUser tau = new TicketApplicationUser();
                tau.ApplicationUser   = user;
                tau.Ticket            = ticket;
                ticket.TicketPriority = model.TicketPriority;
                ticket.TicketStatus   = model.TicketStatus;
                ticket.TicketType     = model.TicketType;
                ticket.TicketApplicationUsers.Add(tau);
                ticket.Created = DateTime.Now;
                ticket.Project = dbContext.Projects.Find(model.ProjectId);

                foreach (var file in Request.Form.Files)
                {
                    TicketAttachment attachment = new TicketAttachment();
                    attachment.ApplicationUser = user;
                    attachment.Ticket          = ticket;
                    attachment.Name            = file.FileName;
                    MemoryStream ms = new MemoryStream();
                    file.CopyTo(ms);
                    attachment.Image = ms.ToArray();

                    ticket.TicketAttachments.Add(attachment);
                }

                dbContext.Tickets.Add(ticket);
                dbContext.SaveChanges();

                if (model.returnToProject)
                {
                    return(RedirectToAction("Tickets", "Projects", new { id = model.ProjectId }));
                }

                return(View("Index"));
            }

            return(BadRequest());
        }