public JsonResult QueryForwardSubmit(string queryid, QueryCommentViewModel queryCommentViewModel) { string[] arr = Session["UserData"] as string[]; string appid = queryCommentViewModel.QueryDetails.ERApplicationId; queryCommentViewModel.Comment.ERApplicationId = appid; queryCommentViewModel.Comment.UserAccountId = arr[0]; queryCommentViewModel.QueryMaster.Is_Active = true; queryCommentViewModel.QueryMaster.QueryParentId = queryCommentViewModel.QueryDetails.QueryParentId; queryCommentViewModel.QueryMaster.ERApplicationId = appid; queryCommentViewModel.QueryDetails.QuerySeq = 1; queryCommentViewModel.QueryDetails.CommentRefId = queryCommentViewModel.Comment.Id; queryCommentViewModel.QueryDetails.QueryParentId = queryCommentViewModel.QueryMaster.Id; queryCommentViewModel.QueryDetails.Status = StatusMasterContext.Collection().Where(x => x.Status == "Query Forward").FirstOrDefault().Id; queryCommentViewModel.QueryDetails.Is_Active = true; QueryUser queryUser = new QueryUser() { SenderId = arr[0], RecieverId = queryCommentViewModel.ReciverIdSelectList[0], QueryId = queryCommentViewModel.QueryDetails.QueryParentId, }; AuditTrails auditTrails = new AuditTrails() { ERApplicationId = appid, FileRefId = queryCommentViewModel.QueryDetails.FileRefId, StatusId = queryCommentViewModel.QueryDetails.Status, QueryDetailsId = queryCommentViewModel.QueryDetails.Id, SenderId = queryUser.SenderId, ReceiverId = queryUser.RecieverId, Is_Active = true, }; string dt = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss").Replace("/", "").Replace(":", "").Replace(" ", ""); queryCommentViewModel.QueryMaster.CustQueryId = "QMID" + dt; queryCommentViewModel.QueryDetails.CustQueryId = "QDID" + dt; AuditTrailsContext.Insert(auditTrails); QueryUserContext.Insert(queryUser); commentContext.Insert(queryCommentViewModel.Comment); QueryDetailsContext.Insert(queryCommentViewModel.QueryDetails); QueryMasterContext.Insert(queryCommentViewModel.QueryMaster); if (TryValidateModel(queryCommentViewModel)) { using (TransactionScope scope = new TransactionScope()) { commentContext.Commit(); AuditTrailsContext.Commit(); QueryDetailsContext.Commit(); QueryUserContext.Commit(); QueryMasterContext.Commit(); scope.Complete(); return(Json("Successfully Query Forward To Selected User.", JsonRequestBehavior.AllowGet)); } } else { return(Json("Something Went Wrong! Try Again Later")); } }
public ActionResult AjaxAdd(string appid, string targetPage, string queryId) { string[] arr = Session["UserData"] as string[]; string userid = arr[0]; object _genericObject; QueryDetails queryDetails; QueryMaster queryMaster; Comment comment; switch (targetPage) { case "QueryCommentRaised": queryDetails = new QueryDetails() { FileRefId = Guid.NewGuid().ToString(), ERApplicationId = appid }; QueryCommentViewModel QueryCommentRaised = new QueryCommentViewModel(); QueryCommentRaised.QueryDetails = queryDetails; if (arr[2] == "coordinator") { ViewBag.ReciverList = ERAppActiveUsersContext.Collection().Where(x => x.ERApplicationId == appid && x.UserAccountId != userid) .Select(d => new { ListItemKey = d.UserAccountId, ListItemValue = d.UserAccount.FirstName + " " + d.UserAccount.LastName + " (" + d.UserAccount.UserRole + ")" }).ToList(); } else if (arr[2] == "Consultant Enhanced Recovery") { ViewBag.ReciverList = ERAppActiveUsersContext.Collection().Where(x => x.ERApplicationId == appid && x.UserAccountId != userid && x.UserAccount.UserRole == "coordinator") .Select(d => new { ListItemKey = d.UserAccountId, ListItemValue = d.UserAccount.FirstName + " " + d.UserAccount.LastName + " (" + d.UserAccount.UserRole + ")" }).ToList(); } else if (arr[2] == "operator") { ViewBag.ReciverList = ERAppActiveUsersContext.Collection().Where(x => x.ERApplicationId == appid && x.UserAccountId != userid && x.UserAccount.UserRole == "Consultant Enhanced Recovery") .Select(d => new { ListItemKey = d.UserAccountId, ListItemValue = d.UserAccount.FirstName + " " + d.UserAccount.LastName + " (" + d.UserAccount.UserRole + ")" }).ToList(); } else { ViewBag.ReciverList = ERAppActiveUsersContext.Collection().Where(x => x.ERApplicationId == appid && x.UserAccountId != userid && x.UserAccount.UserRole != "operator") .Select(d => new { ListItemKey = d.UserAccount.Id, ListItemValue = d.UserAccount.FirstName + " " + d.UserAccount.LastName + " (" + d.UserAccount.UserRole + ")" }).ToList(); } _genericObject = QueryCommentRaised; break; case "QueryCommentForward": QueryCommentViewModel QueryCommentForward = new QueryCommentViewModel(); QueryDetails qd = QueryDetailsContext.Collection().Where(x => x.Id == queryId).FirstOrDefault(); queryDetails = new QueryDetails() { FileRefId = Guid.NewGuid().ToString(), ERApplicationId = appid, QueryParentId = qd.QueryParentId, }; queryMaster = new QueryMaster() { Subject = QueryMasterContext.Collection().Where(d => d.Id == qd.QueryParentId).FirstOrDefault().Subject, }; comment = new Comment() { Text = commentContext.Collection().Where(c => c.Id == qd.CommentRefId).FirstOrDefault().Text, }; QueryCommentForward.QueryDetails = queryDetails; QueryCommentForward.QueryMaster = queryMaster; QueryCommentForward.Comment = comment; QueryUser queryUser = QueryUserContext.Collection().Where(x => x.QueryId == qd.QueryParentId).FirstOrDefault(); if (arr[2] == "coordinator") { // QueryUserContext.Collection().Where(x=>x.QueryId==queryId) var qmc = QueryMasterContext.Collection().Where(e => e.ERApplicationId == appid).ToList(); var query = from p in qmc join q in qmc on p.Id equals q.QueryParentId select new { pid = p.Id, qid = q.Id }; ViewBag.ReciverList = ERAppActiveUsersContext.Collection().Where(x => x.ERApplicationId == appid && x.UserAccountId != userid && x.UserAccountId != queryUser.RecieverId && x.UserAccountId != queryUser.SenderId) .Select(d => new { ListItemKey = d.UserAccountId, ListItemValue = d.UserAccount.FirstName + " " + d.UserAccount.LastName + " (" + d.UserAccount.UserRole + ")" }).ToList(); } else { ViewBag.ReciverList = ERAppActiveUsersContext.Collection().Where(x => x.ERApplicationId == appid && x.UserAccountId != userid && x.UserAccount.UserRole != "operator" && x.UserAccountId != queryUser.RecieverId && x.UserAccountId != queryUser.SenderId) .Select(d => new { ListItemKey = d.UserAccount.Id, ListItemValue = d.UserAccount.FirstName + " " + d.UserAccount.LastName + " (" + d.UserAccount.UserRole + ")" }).ToList(); } _genericObject = QueryCommentForward; break; case "QueryCommentReply": QueryCommentViewModel QueryCommentReply = new QueryCommentViewModel(); queryDetails = new QueryDetails() { ERApplicationId = appid, QueryParentId = QueryDetailsContext.Collection().Where(x => x.Id == queryId).Select(d => d.QueryParentId).FirstOrDefault().ToString(), FileRefId = Guid.NewGuid().ToString() }; QueryCommentReply.QueryDetails = queryDetails; _genericObject = QueryCommentReply; break; case "QueryCommentResolved": _genericObject = new QueryCommentViewModel(); break; case "ForwardApplication": ForwardAppViewModel forwardAppViewModel = new ForwardAppViewModel(); ForwardApplication forwardApplication = new ForwardApplication(); //if(arr[2]=="HoD") if (arr[2] == UserRoleType.ConsultantEnhancedRecovery.GetDisplayName()) { ViewBag.ReciverList = UserAccountContext.Collection().Where(x => (x.UserRole == UserRoleType.Coordinator.ToString()) && x.Id != userid) .Select(d => new { ListItemKey = d.Id, ListItemValue = d.FirstName + " " + d.LastName + " (" + d.UserRole + ")" }).ToList(); } else if (arr[2] == UserRoleType.Coordinator.ToString()) { int CountForward = ForwardApplicationContext.Collection().Where(x => x.ERApplicationId == appid && x.Is_Active == true && x.Sender == userid && (x.FileStatus == FileStatus.ReviewAgain || x.FileStatus == FileStatus.Forward)).Count(); int CountRecommended = ForwardApplicationContext.Collection().Where(x => x.ERApplicationId == appid && x.Is_Active == true && x.Reciever == userid && x.FileStatus == FileStatus.Recommended).Count(); if (CountForward == CountRecommended && CountForward != 0 && CountRecommended != 0) { ViewBag.ReciverList = UserAccountContext.Collection().Where(x => x.UserRole == UserRoleType.DG.ToString() && x.Id != userid) .Select(d => new { ListItemKey = d.Id, ListItemValue = d.FirstName + " " + d.LastName + " (" + d.UserRole + ")" }).ToList(); } else { ViewBag.ReciverList = UserAccountContext.Collection().Where(x => (x.UserRole == UserRoleType.Hod.ToString() || x.UserRole == UserRoleType.Coordinator.ToString() || x.UserRole == UserRoleType.ADG.ToString()) && x.Id != userid) .Select(d => new { ListItemKey = d.Id, ListItemValue = d.FirstName + " " + d.LastName + " (" + d.UserRole + ")" }).ToList(); } } else { ViewBag.ReciverList = UserAccountContext.Collection().Where(x => (x.UserRole == UserRoleType.Hod.ToString() || x.UserRole == UserRoleType.Coordinator.ToString() || x.UserRole == UserRoleType.ADG.ToString()) && x.Id != userid) .Select(d => new { ListItemKey = d.Id, ListItemValue = d.FirstName + " " + d.LastName + " (" + d.UserRole + ")" }).ToList(); } forwardApplication.FileRef = Guid.NewGuid().ToString(); forwardAppViewModel.ForwardApplication = forwardApplication; _genericObject = forwardAppViewModel; break; case "UploadApprovalLetter": UploadApprovalLetterViewModel uploadApprovalLetterViewModel = new UploadApprovalLetterViewModel(); ForwardApplication forwardApplication1 = new ForwardApplication() { FileRef = Guid.NewGuid().ToString(), ERApplicationId = appid }; uploadApprovalLetterViewModel.ForwardApplication = forwardApplication1; _genericObject = uploadApprovalLetterViewModel; break; default: _genericObject = null; break; } if (null != _genericObject) { ViewBag.appid = appid; return(View(targetPage, _genericObject)); } else { return(Content("<div class=\"alert alert-danger\" role=\"alert\"> An Error has occured </div>")); } }