/// <summary> /// Send reminder mail to selected approvals for approving the ticket /// </summary> /// <param name="listOfApproverIds">List OF Approvals objects</param> /// <param name="ticket">Ticket Object</param> public void SendReminder(List <Approvals> listOfApprovers, Tickets ticket) { try { if (ticket.RequestedBy == null) { TicketController cntrlr = new TicketController(); ticket = cntrlr.GetTicketObjectData(ticket.TicketId); } if (listOfApprovers != null) { List <Approvals> lstApprovers = new List <Approvals>(); foreach (var singleapprover in listOfApprovers) { UserController userController = new UserController(); // Users approverUser = userController.GetUser(singleapprover.Approver.UserId); Approvals approver = new Approvals(); approver.Approver = singleapprover.Approver; approver.ApprovalState = ApprovalState.Pending; approver.ApproverComments = singleapprover.ApproverComments; lstApprovers.Add(approver); } if (ticket != null) { ticket.Approvals = lstApprovers; } //Get FinalCRS statusID of ticket while sending mail EMIETicket savedEmieTicket = DbEntity.EMIETickets.Single(o => o.TicketId == ticket.TicketId); ticket.FinalTicketStatus = (TicketStatus)savedEmieTicket.FinalCRStatusId; CommonFunctions.SendMail(ticket, MailMessageType.SendReminder); } } catch (Exception) { throw; } }
/// <summary> /// This method will approve or reject the ticket status /// </summary> /// <param name="ticketIds"> contain list of tickets</param> /// <param name="isApproved">If true will approve the status of the tickets else will reject</param> /// <returns>returns number of succesfully updation</returns> public JsonResult PerformRequest(List <int> ticketIds, bool isApproved, int loggedInUserId, string rejectionComments) { int finalTicketStatus = 0; List <int> updatedTicketList = new List <int>(); string Request = string.Empty; string description = string.Empty; int state = 0; if (!ModelState.IsValid || ticketIds == null || loggedInUserId == 0) { return(null); } try { for (int ticketcount = 0; ticketcount < ticketIds.Count(); ticketcount++) { int ticketid = ticketIds[ticketcount]; //Getting the list of the tickets and updating the individual status of the ticket in the database through enum List <EMIETicketAproval> ticketApproval = (from approval in DbEntity.EMIETicketAprovals join userBpurolemapping in DbEntity.UserRoleBPUMappings on approval.UserRoleBPUMappingId equals userBpurolemapping.ID join user in DbEntity.Users on userBpurolemapping.UserId equals user.UserId where (approval.TicketId == ticketid && user.UserId == loggedInUserId) select approval).ToList(); if (ticketApproval.Count > 0) { foreach (var approval in ticketApproval) { if (approval.TicketStateId == (int)ApprovalState.Pending) { string UserName = DbEntity.Users.Where(userid => userid.UserId == loggedInUserId).Select(username => username.UserName).FirstOrDefault().ToString(); if (isApproved) { state = (int)ApprovalState.Approved; Request = "ApproveRequest"; description = string.Format(Constants.TicketStatus, ticketid, Constants.Approved, UserName); } else { state = (int)ApprovalState.Rejected; Request = "RejectRequest"; description = string.Format(Constants.TicketStatus, ticketid, Constants.Rejected, UserName); } approval.TicketStateId = state; approval.ModifiedById = loggedInUserId; approval.ModifiedDate = DateTime.Now; } else { //this function will add the newly joined emie champ for the respective ticket AddNewlyAddedEMIEChamp(loggedInUserId, ticketid, isApproved); } } } else { //this function will add the newly joined emie champ for the respective ticket AddNewlyAddedEMIEChamp(loggedInUserId, ticketid, isApproved); } //UserObj = DbEntity.Users.Where(userid => userid.UserId == loggedInUserId).Select(username => username.UserName).FirstOrDefault().ToString(); #region Logger //this section will log the every single operation performed Loggers loggers = new Loggers { ActionMethod = Request, Description = description, Operation = Constants.Update, UserID = loggedInUserId }; logger = LoggerObj.LoggerMethod(loggers); DbEntity.Loggers.Add(logger); #endregion DbEntity.SaveChanges(); finalTicketStatus = FinalCRStatus(ticketid); //Changing the final cr status of ticket EMIETicket emieTicket = DbEntity.EMIETickets.SingleOrDefault(o => o.TicketId == ticketid); emieTicket.FinalCRStatusId = finalTicketStatus; //add rejection reason to emie ticket table if (rejectionComments != null) { emieTicket.RejectedReason = rejectionComments; } DbEntity.SaveChanges(); updatedTicketList.Add(ticketid); //Need this comment // Please uncomment this code once Approve/Reject functionality is working for other logged in users #region Send Mails for (int cnt = 0; cnt < updatedTicketList.Count(); cnt++) { TicketController controller = new TicketController(); Tickets ticket = controller.GetTicketObjectData(updatedTicketList[ticketcount]); if (rejectionComments != null) { ticket.ProductionFailureComments = rejectionComments; } if (ticket.FinalTicketStatus == TicketStatus.Approved || ticket.FinalTicketStatus == TicketStatus.PartiallyApproved) { CommonFunctions.SendMail(ticket, MailMessageType.RequestApproved); } else if (ticket.FinalTicketStatus == TicketStatus.Rejected) { CommonFunctions.SendMail(ticket, MailMessageType.RequestRejected); } } #endregion Send Mails } } catch (Exception) { throw; } return(Json(updatedTicketList, JsonRequestBehavior.AllowGet)); }