public async Task <IActionResult> Index() { string username; if (!User.Identity.IsAuthenticated) { List <Ticket> empty = new List <Ticket>(); var emptyList = new UserTicketsViewModel(); emptyList.UserTickets = empty; return(View(emptyList)); } else { username = User.Identity.Name; } var user = await _service.FindUserIdByUserName(username); //Here i get a user. just checking if this user is valid, or anything else that needs a check. if (user == null) { return(RedirectToPage("Register")); } var list = new UserTicketsViewModel { UserTickets = await _service.MySendTickets(username) }; return(View(list)); }
public ActionResult UserTickets() { var userId = User.Identity.GetUserId(); IEnumerable <Project> projects; IEnumerable <Ticket> assignedTickets; IEnumerable <Ticket> submittedTickets; if (User.IsInRole("Developer")) { assignedTickets = userId.ListUserTickets().OrderBy(t => t.Priority.Id); } else { assignedTickets = null; } projects = userId.ListUserProjects().OrderByDescending(p => p.Deadline); submittedTickets = db.Tickets.Where(t => t.SubmitterId == userId).Where(t => t.Status.Name != "Resolved").OrderBy(t => t.Submitted).ToList(); var model = new UserTicketsViewModel() { AssignedProjects = projects, AssignedTickets = assignedTickets, SubmittedTickets = submittedTickets }; return(View(model)); }
public ActionResult GetByUserId(int id) { var userTickets = new UserTicketsViewModel() { Tickets = (from u in ctx.Users join c in ctx.TransportCards on u.Id equals c.User.Id join t in ctx.Tickets on c.Id equals t.Card.Id where u.Id == id select new UserTicketsViewModel { UserId = u.Id, UserName = u.Name, UserSurname = u.Surname, CardType = c.CardType, IsActive = c.IsActive, TicketType = t.TicketType, ValidFromDate = t.ValidFromDate } ).ToList() }; return(View(userTickets)); }