public bool assignUserToTicket(int userID, int ticketID) { var user = getCurrentUser(); if (user.UserID == userID) { return false; } if (user.UserType == UserType.Customer) { return false; } var assignedToUser = getUser(userID); if (assignedToUser.UserType != UserType.Help) { return false; } var ticket = getTicket(ticketID); if (!assignedToUser.UserTicketLinks.Select(utl => utl.Ticket).Contains(ticket)) { var userTicketLink = new UserTicketLink(); userTicketLink.UserID = assignedToUser.UserID; userTicketLink.User = assignedToUser; userTicketLink.TicketID = ticket.TicketID; userTicketLink.Ticket = ticket; db.UserTicketLinks.Add(userTicketLink); ticket.TicketState = TicketState.Open; var ticketEvent = new TicketEvent(); ticketEvent.NewTicketState = TicketState.Open; ticketEvent.text = "Ticket " + ticket.TicketID + " ( " + ticket.TicketTitle + " ) assigned to " + assignedToUser.Email + " by " + user.Email; ticketEvent.TicketID = ticket.TicketID; ticketEvent.Ticket = ticket; db.TicketEvents.Add(ticketEvent); db.SaveChanges(); } return true; }
public bool createTicket(Ticket ticket) { ticket.OwnerUserID = getCurrentUserId(); db.Tickets.Add(ticket); var user = getCurrentUser(); var userTicketLink = new UserTicketLink(); userTicketLink.UserID = user.UserID; userTicketLink.User = user; userTicketLink.TicketID = ticket.TicketID; userTicketLink.Ticket = ticket; db.UserTicketLinks.Add(userTicketLink); var ticketEvent = new TicketEvent(); ticketEvent.text = "Ticket created"; db.TicketEvents.Add(ticketEvent); db.SaveChanges(); return true; }