Beispiel #1
0
        public async Task <JsonResult> ApplicationActionSubmit(ForwardAppViewModel forwardAppViewModel, string appid)
        {
            ForwardApplication forwardApplication;
            ERAppActiveUsers   eRAppActiveUsers;

            string[] arr          = Session["UserData"] as string[];
            bool     modelIsValid = false;
            string   msg          = "ERROR";

            forwardAppViewModel.Comment.ERApplicationId = appid;
            forwardAppViewModel.Comment.UserAccountId   = arr[0];

            string[] reciverlist = forwardAppViewModel.ReciverIdSelectList != null ? forwardAppViewModel.ReciverIdSelectList : null;

            if (reciverlist != null && forwardAppViewModel.ForwardApplication.FileStatus == FileStatus.Forward)
            {
                var userlist = forwardAppViewModel.ReciverIdSelectList.Except(ERAppActiveUsersContext.Collection().Where(x => x.ERApplicationId == appid).Select(y => y.UserAccountId).ToList());
                foreach (string user in userlist)
                {
                    eRAppActiveUsers = new ERAppActiveUsers()
                    {
                        ERApplicationId = appid,
                        UserAccountId   = user,
                        Dept_Id         = null,
                        Is_Active       = true,
                        Status          = null
                    };
                    ERAppActiveUsersContext.Insert(eRAppActiveUsers);
                }
            }

            string userid      = arr[0];
            string senderid    = "";
            string auditstatus = "";

            switch (forwardAppViewModel.ForwardApplication.FileStatus)
            {
            case FileStatus.Forward:
                auditstatus = "S102";
                msg         = "Successfully Forward Application To Selected Users";
                break;

            case FileStatus.Recommended:
                auditstatus = "S105";
                senderid    = ForwardApplicationContext.Collection().Where(x => x.Reciever == userid && x.ERApplicationId == appid && (x.FileStatus == FileStatus.Forward || x.FileStatus == FileStatus.ReviewAgain) && x.Is_Active == true).FirstOrDefault().Sender;
                reciverlist = new string[] { senderid };
                msg         = "Successfully Application Recommended";
                break;

            case FileStatus.CommentBack:
                auditstatus = "S109";
                senderid    = ForwardApplicationContext.Collection().Where(x => x.Reciever == userid && x.ERApplicationId == appid && (x.FileStatus == FileStatus.Forward || x.FileStatus == FileStatus.ReviewAgain) && x.Is_Active == true).FirstOrDefault().Sender;
                reciverlist = new string[] { senderid };
                msg         = "Successfully Comment Back";
                if (arr[2] == UserRoleType.DG.ToString())
                {
                    await ForwardApplicationContext.Collection().Where(x => x.ERApplicationId == appid && x.Sender == senderid && x.Reciever == userid && (x.FileStatus == FileStatus.Forward || x.FileStatus == FileStatus.ReviewAgain) && x.Is_Active == true).ForEachAsync(x => x.Is_Active = false);

                    await AuditTrailsContext.Collection().Where(x => x.ERApplicationId == appid && x.SenderId == senderid && x.ReceiverId == userid && x.Is_Active == true).ForEachAsync(x => x.Is_Active = false);
                }
                else
                {
                    await ForwardApplicationContext.Collection().Where(x => x.ERApplicationId == appid && x.Sender == senderid && (x.FileStatus == FileStatus.Forward || x.FileStatus == FileStatus.ReviewAgain) && x.Is_Active == true).ForEachAsync(x => x.Is_Active = false);

                    await ForwardApplicationContext.Collection().Where(x => x.ERApplicationId == appid && x.FileStatus == FileStatus.Recommended && x.Reciever == senderid && x.Is_Active == true).ForEachAsync(d => d.Is_Active = false);

                    await AuditTrailsContext.Collection().Where(x => x.ERApplicationId == appid && x.StatusId == "S105" && x.Is_Active == true).ForEachAsync(d => d.Is_Active = false);

                    await AuditTrailsContext.Collection().Where(x => x.ERApplicationId == appid && x.SenderId == senderid && x.Is_Active == true).ForEachAsync(x => x.Is_Active = false);
                }
                break;

            case FileStatus.ReviewAgain:
                string DGID      = UserAccountContext.Collection().Where(x => x.UserRole == UserRoleType.DG.ToString()).FirstOrDefault().Id;
                int    countdgid = ERAppActiveUsersContext.Collection().Where(x => x.UserAccountId == DGID && x.ERApplicationId == appid && x.Is_Active == true).Count();
                if (countdgid > 0)
                {
                    reciverlist = new string[] { DGID };
                }
                else
                {
                    reciverlist = ForwardApplicationContext.Collection().Where(x => x.ERApplicationId == appid && x.Sender == userid && (x.FileStatus == FileStatus.Forward || x.FileStatus == FileStatus.ReviewAgain) && x.Is_Active == false).Select(d => d.Reciever).Distinct().ToArray();
                    if (reciverlist == null || reciverlist.Length == 0)
                    {
                        return(Json("NCR", JsonRequestBehavior.AllowGet));
                    }
                }
                auditstatus = "S106";
                msg         = "Comment Resolved Successfully";
                break;

            default: return(Json(msg, JsonRequestBehavior.AllowGet));
            }

            foreach (string x in reciverlist)
            {
                forwardApplication = new ForwardApplication()
                {
                    Reciever     = x,
                    Sender       = arr[0],
                    FileRef      = forwardAppViewModel.ForwardApplication.FileRef,
                    CommentRefId = forwardAppViewModel.Comment.Id,
                    // Subject = forwardAppViewModel.ForwardApplication.Subject,
                    ERApplicationId = appid,
                    Is_Active       = true,
                    FileStatus      = forwardAppViewModel.ForwardApplication.FileStatus
                };
                ForwardApplicationContext.Insert(forwardApplication);

                AuditTrails auditTrails = new AuditTrails()
                {
                    ERApplicationId = appid,
                    FileRefId       = forwardAppViewModel.ForwardApplication.FileRef,
                    StatusId        = auditstatus,
                    // QueryDetailsId = null,
                    SenderId   = arr[0],
                    ReceiverId = x,
                    Is_Active  = true,
                };

                AuditTrailsContext.Insert(auditTrails);
            }

            modelIsValid = TryValidateModel(forwardAppViewModel.Comment);
            if (modelIsValid)
            {
                commentContext.Insert(forwardAppViewModel.Comment);

                using (TransactionScope scope = new TransactionScope())
                {
                    commentContext.Commit();
                    ERAppActiveUsersContext.Commit();
                    ForwardApplicationContext.Commit();
                    AuditTrailsContext.Commit();

                    scope.Complete();
                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                msg = "ERROR";
                return(Json(msg, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #2
0
        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>"));
            }
        }