public JsonResult ProcessForgotPasswordRequest(string email)
        {
            try
            {
                if (string.IsNullOrEmpty(email) || email.Length < 5)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Email Address" }));
                }

                var passObj = new EmailResendObj
                {
                    Email = email
                };

                var response = new PortalUserManager().SendPasswordResetEmail(passObj, "");
                if (response?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.FriendlyMessage) ? "Process Failed! Unable to process your request. Please try again later" : response.Status.Message.FriendlyMessage }));
                }

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
    public static PortalUserManager Create(string connectionString)
    {
        UserStore <PortalUser> userStore = new UserStore <PortalUser>(PortalDbContext.Create(connectionString));

        PortalUserManager manager = new PortalUserManager(userStore);

        // Configure validation logic for usernames
        manager.UserValidator = new UserValidator <PortalUser>(manager)
        {
            AllowOnlyAlphanumericUserNames = true,
            RequireUniqueEmail             = true
        };

        // Configure validation logic for passwords
        manager.PasswordValidator = new PasswordValidator
        {
            RequiredLength          = 6,
            RequireNonLetterOrDigit = true,
            RequireDigit            = true,
            RequireLowercase        = true,
            RequireUppercase        = true,
        };

        return(manager);
    }
        public JsonResult ProcessPasswordResetRequest(string myUsername)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                //var bearerAuth = MvcApplication.GetSessionBearerData(userData.Username);
                //var authToken = MvcApplication.GetSessionAuthData(userData.Username);

                //if (string.IsNullOrEmpty(bearerAuth) || bearerAuth.Length < 5)
                //{
                //    return Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid User Session! Please Re-Login" });
                //}

                //if (string.IsNullOrEmpty(authToken) || authToken.Length < 5)
                //{
                //    return Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid User Session! Please Re-Login" });
                //}

                if (string.IsNullOrEmpty(myUsername) || myUsername.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Username" }));
                }


                var passObj = new ResetPasswordObj
                {
                    Email       = myUsername,
                    AdminUserId = userData.UserId,
                };


                var changePassword = new PortalUserManager().ResetPassword(passObj, userData.Username);
                if (changePassword?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                //MvcApplication.SetSessionBearerData(changePassword.Status.CustomSetting, userData.Username);
                //MvcApplication.SetSessionAuthData(changePassword.Status.CustomToken, userData.Username);

                if (!changePassword.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(changePassword.Status.Message.FriendlyMessage) ? "Process Failed! Unable to change your password" : changePassword.Status.Message.FriendlyMessage }));
                }

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = changePassword.NewPassword }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
        public ActionResult Index(int?ExpenseRequisitionId)
        {
            try
            {
                ViewBag.Error = "";
                #region current user session check

                var userData = MvcApplication.GetUserData(User.Identity.Name);
                if (userData == null || userData.UserId < 1)
                {
                    ViewBag.Error = "Session Has Expired! Please Re-Login";
                    return(View(new List <WorkflowItemObj>()));
                }

                #endregion

                var searchObjForUser = new UserSearchObj
                {
                    AdminUserId = userData.UserId,
                    Status      = -2,
                    StopDate    = "",
                    StartDate   = "",
                    UserId      = 0,
                };
                var retValForUsers = new PortalUserManager().LoadUsers(searchObjForUser, userData.Username);
                var usersList      = retValForUsers.Users.Where(m => m.Status == 1).ToList();
                Session["_usersList_"] = usersList;
                var searchObj = new  WorkflowItemSearchObj
                {
                    AdminUserId    = userData.UserId,
                    WorkflowItemId = 0,
                    Status         = -2,
                    StartDate      = "",
                    StopDate       = "",
                };
                var retVal = WorkflowItemServices.LoadWorkflowItems(searchObj, userData.Username);
                if (retVal?.Status == null)
                {
                    ViewBag.Error = " WorkflowItem list is empty!";
                    return(View(new List <WorkflowItemObj>()));
                }

                if (retVal.WorkflowItems == null || !retVal.WorkflowItems.Any())
                {
                    return(View(new List <WorkflowItemObj>()));
                }
                var WorkflowItems = retVal.WorkflowItems.OrderBy(m => m.WorkflowItemId).Where(x => x.ExpenseRequisitionId == ExpenseRequisitionId).ToList();
                return(View(WorkflowItems));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new List <WorkflowItemObj>()));
            }
        }
        public ActionResult EmailChecker(string userId, string userCode)
        {
            try
            {
                ViewBag.Error = "";
                if (string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(userCode))
                {
                    ViewBag.Error = "Invalid Activation Link";
                    return(View());
                }

                userId   = userId.CleanEncryptedString();
                userCode = userCode.CleanEncryptedString();

                var username = userId.DecryptUrlItem();
                var code     = userCode.DecryptUrlItem();

                if (string.IsNullOrEmpty(username) || username.Length < 5)
                {
                    ViewBag.Error = "Invalid Activation Link";
                    return(View());
                }

                if (string.IsNullOrEmpty(code) || code.Length < 5)
                {
                    ViewBag.Error = "Invalid Activation Link";
                    return(View());
                }

                var confirm = new EmailConfirmObj
                {
                    ConfirmationCode = code.Trim(),
                    Email            = username
                };

                var response = new PortalUserManager().ConfirmUserEmail(confirm, "");
                if (response?.Status == null)
                {
                    ViewBag.Error = "Unable to confirm your email. Please try again later";
                    return(View());
                }
                if (!response.Status.IsSuccessful)
                {
                    ViewBag.Error = string.IsNullOrEmpty(response.Status.Message.FriendlyMessage) ? "Unable to confirm your email. Please try again later" : response.Status.Message.FriendlyMessage;
                    return(View());
                }

                return(RedirectToAction("Login"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = "Error Occurred! Please try again later";
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View());
            }
        }
Example #6
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            filterContext.Controller.ViewBag.IsSuccessful = false;

            var modelList = filterContext.ActionParameters.Where(ap => ap.Key == "model").ToList();

            if (modelList.IsNullOrEmpty())
            {
                filterContext.Controller.ViewBag.Error = "Invalid update information";
                return;
            }
            if (!modelList.Any() || modelList.Count != 1)
            {
                filterContext.Controller.ViewBag.Error = "Invalid update information";
                return;
            }

            if (!(modelList[0].Value is ResetPasswordContract model))
            {
                filterContext.Controller.ViewBag.Error = "Invalid update information";
                return;
            }

            if (!GenericVal.Validate(model, out var msg))
            {
                filterContext.Controller.ViewBag.Error = msg;
                return;
            }

            var contract = new ControlUserObj
            {
                AdminUserId = 1,
                Email       = model.Username,
                ControlType = (int)UserControlType.Locked_Out
            };

            var lockUser = new PortalUserManager().LockUser(contract, model.Username);

            if (lockUser == null)
            {
                filterContext.Controller.ViewBag.Error = "Process Failed! Unable to unlock account";
                return;
            }
            if (!lockUser.Status.IsSuccessful)
            {
                filterContext.Controller.ViewBag.Error = string.IsNullOrEmpty(lockUser.Status.Message.FriendlyMessage) ? "Process Failed! Unable to update user's account" : lockUser.Status.Message.FriendlyMessage;
                return;
            }

            filterContext.Controller.ViewBag.IsSuccessful = true;
            base.OnActionExecuting(filterContext);
        }
Example #7
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            filterContext.Controller.ViewBag.IsSuccessful = false;
            filterContext.Controller.ViewBag.Error        = "";

            var modelList = filterContext.ActionParameters.Where(ap => ap.Key == "model").ToList();

            if (modelList.IsNullOrEmpty())
            {
                filterContext.Controller.ViewBag.Error = "Invalid update information";
                return;
            }
            if (!modelList.Any() || modelList.Count != 1)
            {
                filterContext.Controller.ViewBag.Error = "Invalid update information";
                return;
            }

            if (!(modelList[0].Value is ResetPasswordContract model))
            {
                filterContext.Controller.ViewBag.Error = "Invalid update information";
                return;
            }
            if (!GenericVal.Validate(model, out var msg))
            {
                filterContext.Controller.ViewBag.Error = msg;
                return;
            }

            var contract = new ResetPasswordObj
            {
                AdminUserId = 1,
                Email       = model.Username,
            };

            var passReset = new PortalUserManager().ResetPassword(contract, model.Username);

            if (passReset == null)
            {
                filterContext.Controller.ViewBag.Error = "Process Failed! Unable to reset password";
                return;
            }
            if (!passReset.Status.IsSuccessful)
            {
                filterContext.Controller.ViewBag.Error = string.IsNullOrEmpty(passReset.Status.Message.FriendlyMessage) ? "Process Failed! Unable to update password" : passReset.Status.Message.FriendlyMessage;
                return;
            }

            filterContext.Controller.ViewBag.IsSuccessful    = true;
            filterContext.Controller.ViewBag.ThisNewPassword = passReset.NewPassword;
            base.OnActionExecuting(filterContext);
        }
        public JsonResult ProcessPasswordResetRequest(ResetUserAccessInfoObj resetObj)
        {
            try
            {
                if (resetObj == null || string.IsNullOrEmpty(resetObj.Email) ||
                    string.IsNullOrEmpty(resetObj.ConfirmationCode) || resetObj.Email.Length < 5 ||
                    resetObj.ConfirmationCode.Length < 5)
                {
                    return(Json(new { IsSuccessful = false, Error = "Invalid Password Reset Information" }));
                }

                if (string.IsNullOrEmpty(resetObj.NewPassword) || resetObj.NewPassword.Length < 3)
                {
                    return(Json(new { IsSuccessful = false, Error = "New Password must be at least 3 characters" }));
                }

                if (string.IsNullOrEmpty(resetObj.ConfirmPassword) || resetObj.ConfirmPassword.Length < 3)
                {
                    return(Json(new { IsSuccessful = false, Error = "Confirm Password must be at least 3 characters" }));
                }

                if (string.Compare(resetObj.NewPassword, resetObj.ConfirmPassword, StringComparison.CurrentCultureIgnoreCase) != 0)
                {
                    return(Json(new { IsSuccessful = false, Error = "New Password and Confirm Password must match" }));
                }

                var passObj = new PasswordResetConfirmObj
                {
                    Password         = resetObj.NewPassword,
                    Email            = resetObj.Email,
                    ConfirmationCode = resetObj.ConfirmationCode,
                };

                var changePassword = new PortalUserManager().ProcessPasswordReset(passObj, "");
                if (changePassword?.Status == null)
                {
                    return(Json(new { IsSuccessful = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!changePassword.Status.IsSuccessful)
                {
                    return(Json(new { IsSuccessful = false, Error = string.IsNullOrEmpty(changePassword.Status.Message.FriendlyMessage) ? "Process Failed! Unable to reset your password" : changePassword.Status.Message.FriendlyMessage }));
                }

                return(Json(new { IsSuccessful = true, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
        public JsonResult ProcessProfileUpdate(EditUserObj model)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (model.UserId < 1)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = "Invalid Email Address" }));
                }

                if (string.IsNullOrEmpty(model.FirstName) || model.FirstName.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = "First Name must be at least 2 characters" }));
                }

                if (string.IsNullOrEmpty(model.LastName) || model.LastName.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = "Last Name must be at least 2 characters" }));
                }

                if (string.IsNullOrEmpty(model.MobileNumber) || model.MobileNumber.Length != 11)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = "Invalid Mobile Number" }));
                }

                model.AdminUserId = userData.UserId;
                var retVal = new PortalUserManager().ModifyUser(model, userData.Email);
                if (retVal == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = "Unable to update your profile at this time" }));
                }

                if (!retVal.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, Error = string.IsNullOrEmpty(retVal.Status.Message.FriendlyMessage) ? "Unable to update your profile at this time!" : retVal.Status.Message.FriendlyMessage }));
                }

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
        public ActionResult ForgotPassword(PasswordRetrievalContract model)
        {
            ViewBag.Error   = "";
            ViewBag.Success = "";
            try
            {
                if (string.IsNullOrEmpty(model.Email) || model.Email.Length < 5)
                {
                    ViewBag.Error = "Invalid / Empty Email Address";
                    return(View(model));
                }

                var passObj = new EmailResendObj
                {
                    Email = model.Email
                };

                var response = new PortalUserManager().SendPasswordResetEmail(passObj, "");
                if (response?.Status == null)
                {
                    ViewBag.Error = "Error Occurred! Please try again late";
                    return(View(model));
                }

                if (!response.Status.IsSuccessful)
                {
                    ViewBag.Error = string.IsNullOrEmpty(response.Status.Message.FriendlyMessage)
                                ? "Process Failed! Unable to process your request. Please try again later"
                                : response.Status.Message.FriendlyMessage;
                    return(View(model));
                }

                model.Email     = "";
                ViewBag.Success = "Password Retrieval Email Was Sent";
                return(View(model));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(model));
            }
        }
        public ActionResult MyProfile()
        {
            try
            {
                ViewBag.Error = "";
                var userData = MvcApplication.GetUserData(User.Identity.Name);
                if (userData == null || userData.UserId < 1)
                {
                    ModelState.AddModelError("", "Invalid Profile Session");
                    return(View());
                }

                //var bearerAuth = MvcApplication.GetSessionBearerData(userData.Username);

                var searchObj = new UserSearchObj
                {
                    AdminUserId = userData.UserId,
                    UserId      = userData.UserId,
                    StartDate   = "",
                    Status      = -5,
                    StopDate    = ""
                };

                var matchingProfiles = new PortalUserManager().GetPortalUser(searchObj, userData.Username);
                if (matchingProfiles?.Status == null || !matchingProfiles.Status.IsSuccessful || matchingProfiles.Users.Count != 1)
                {
                    return(View(new UserItemObj()));
                }
                var myProfile = matchingProfiles.Users[0];

                return(View(myProfile));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new UserItemObj()));
            }
        }
        public ActionResult EmailConfirmMessage(string thisUsername)
        {
            try
            {
                ViewBag.RegUsername = "";
                ViewBag.Error       = "";
                if (string.IsNullOrEmpty(thisUsername) || thisUsername.Length < 5)
                {
                    return(View());
                }
                var modelObj = new EmailResendObj
                {
                    Email = thisUsername
                };

                var response = new PortalUserManager().ResendActivationEmail(modelObj, "");
                if (response?.Status == null)
                {
                    ViewBag.Error = "Unable to resend email at this time. Please try again later";
                    return(View());
                }
                if (!response.Status.IsSuccessful)
                {
                    ViewBag.Error = string.IsNullOrEmpty(response.Status.Message.FriendlyMessage) ? "Unable to resend email at this time. Please try again later" : response.Status.Message.FriendlyMessage;
                    return(View());
                }

                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.Error = "Unable to resend email at this time. Please try again later";
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View());
            }
        }
Example #13
0
        public ActionResult AddWorkflowDetail(int WorkflowTaskId)
        {
            try
            {
                ViewBag.Error        = "";
                ViewBag.SessionError = "";

                #region Client Product productItem Session Check

                var userClientSession = (AppSession)Session["_UserClientSession_"];
                if (userClientSession == null || userClientSession.ClientId < 1 || userClientSession.ProductId < 1 || userClientSession.ProductItemId < 1)
                {
                    return(RedirectToAction("Index", "Dashboard"));
                }

                #endregion

                #region current user check

                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();
                if (userData.UserId < 1)
                {
                    ViewBag.SessionError = "Your session has expired! Please re-login";
                    return(View(new RegWorkflowDetailObj()));
                }

                #endregion

                #region current Id check

                if (WorkflowTaskId < 1)
                {
                    ViewBag.Error = "Invalid selection";
                    return(View(new RegWorkflowDetailObj()));
                }

                #endregion

                #region get current workflow task from service

                var searchObj = new WorkflowTaskSearchObj
                {
                    AdminUserId    = userData.UserId,
                    WorkflowTaskId = 0,
                    Status         = -1000
                };
                var retVal           = WorkflowTaskServices.LoadWorkflowTasks(searchObj, userData.Username);
                var WorkflowTaskList = retVal.WorkflowTasks.ToList();

                var assigneeflowTask = WorkflowTaskList.Find(m => m.WorkflowTaskId == WorkflowTaskId);
                if (assigneeflowTask == null || assigneeflowTask.WorkflowTaskId < 1)
                {
                    ViewBag.Error = "Error Occurred! Unable to process selected item";
                    return(View(new RegWorkflowDetailObj()));
                }
                Session["_CurrentSelWorkflowTask_"] = assigneeflowTask;

                #endregion

                #region extract app users name


                var searchObj2 = new UserSearchObj
                {
                    AdminUserId = userData.UserId,
                    Status      = -2,
                    StopDate    = "",
                    StartDate   = "",
                    UserId      = 0,
                };

                var retValForUsers = new PortalUserManager().LoadUsers(searchObj2, userData.Username);
                var userList       = retValForUsers.Users.ToList();
                Session["_UserList_"] = userList;

                #endregion

                #region get requisitions and extract beneficiaryId and general remark for this Task

                var searchObjForReq = new ExpenseRequisitionSearchObj
                {
                    AdminUserId          = userData.UserId,
                    ExpenseRequisitionId = 0,
                    Status = -1000
                };
                var retValForReq = ExpenseLookupServices.LoadExpenseRequisitions(searchObjForReq, userData.Username);
                if (retValForReq?.Status == null)
                {
                    ViewBag.Error = "Error Occurred! Please try again later";
                    return(View(new RegWorkflowDetailObj()));
                }
                Session["_ExpenseRequisitionList_"] = retValForReq.ExpenseRequisitions.ToList();
                var currentReq = retValForReq.ExpenseRequisitions.FirstOrDefault(m => m.ExpenseRequisitionId == assigneeflowTask.ExpenseRequisitionId);
                if (currentReq == null)
                {
                    ViewBag.Error = "Error Occurred! Unable to process selected item";
                    return(View(new RegWorkflowDetailObj()));
                }
                var BeneficiaryId = currentReq.ExpenseRequisitionItems.FirstOrDefault().BeneficiaryId;

                #endregion

                #region get beneficiary from service and extract benficiary name using beneficiary id from requisitions

                var searchObjForBene = new BeneficiarySearchObj
                {
                    AdminUserId   = userData.UserId,
                    BeneficiaryId = 0,
                    Status        = -1000
                };
                var retValForBene = BeneficiaryServices.LoadBeneficiaries(searchObjForBene, userData.Username);

                if (retValForBene.Beneficiaries.Count < 1)
                {
                    ViewBag.Error = "Error Occurred! Unable to process selected item";
                    return(View(new RegWorkflowDetailObj()));
                }
                var beneficiaryName = retValForBene.Beneficiaries.FirstOrDefault(m => m.BeneficiaryId == BeneficiaryId);
                Session["_BeneficiaryList_"] = retValForBene.Beneficiaries.ToList();

                #endregion

                return(View(new RegWorkflowDetailObj
                {
                    GeeneralRemark = currentReq.GeneralRemark,
                    BeneficiaryName = beneficiaryName.FirstName + " " + beneficiaryName.LastName
                }));
            }
            catch (Exception ex)
            {
                ViewBag.Error = "Error Occurred! Please try again later";
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new RegWorkflowDetailObj()));
            }
        }
Example #14
0
        public JsonResult ProcessEditUserRequest(PortalUserViewModel portalUser)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                //var bearerAuth = MvcApplication.GetSessionBearerData(userData.Username);
                //var authToken = MvcApplication.GetSessionAuthData(userData.Username);

                //if (string.IsNullOrEmpty(bearerAuth) || bearerAuth.Length < 5)
                //{
                //    return Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid User Session! Please Re-Login" });
                //}

                //if (string.IsNullOrEmpty(authToken) || authToken.Length < 5)
                //{
                //    return Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid User Session! Please Re-Login" });
                //}

                if (portalUser == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid User Item" }));
                }

                if (string.IsNullOrEmpty(portalUser.FirstName) || portalUser.FirstName.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "First Name is required" }));
                }

                if (string.IsNullOrEmpty(portalUser.LastName) || portalUser.LastName.Length < 2)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Last Name is required" }));
                }

                if (string.IsNullOrEmpty(portalUser.Email) || portalUser.Email.Length < 5)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Email is required" }));
                }


                var passObj = new EditUserObj
                {
                    UserId       = portalUser.UserId,
                    FirstName    = portalUser.FirstName,
                    LastName     = portalUser.LastName,
                    AdminUserId  = userData.UserId,
                    MobileNumber = portalUser.MobileNumber,
                };


                var response = new PortalUserManager().ModifyUser(passObj, userData.Username);
                if (response == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }


                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.FriendlyMessage) ? "Process Failed! Unable to add role" : response.Status.Message.FriendlyMessage }));
                }

                var updateRole = new EditUserRoleObj
                {
                    AdminUserId = userData.UserId,
                    UserId      = portalUser.UserId,
                    RoleIds     = string.Join(",", portalUser.MyRoleIds)
                };

                var response2 = new PortalRoleManager().UpdateUserRoles(updateRole, userData.Username);
                if (response2 == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }


                if (!response2.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.FriendlyMessage) ? "Process Failed! Unable to add role" : response.Status.Message.FriendlyMessage }));
                }

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
Example #15
0
        public ActionResult LoadUsers()
        {
            var add = new NameValueObject {
                Id = 0, Name = "-- Empty User List --"
            };

            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name);
                if (userData == null || userData.UserId < 1)
                {
                    return(Json(new List <NameValueObject> {
                        add
                    }, JsonRequestBehavior.AllowGet));
                }

                var searchObj = new UserSearchObj
                {
                    AdminUserId = userData.UserId,
                    Status      = -2,
                    StopDate    = "",
                    StartDate   = "",
                    UserId      = 0
                };

                var retVal = new PortalUserManager().LoadUsers(searchObj, userData.Username);
                if (retVal?.Status == null)
                {
                    return(Json(new List <NameValueObject> {
                        add
                    }, JsonRequestBehavior.AllowGet));
                }

                if (!retVal.Status.IsSuccessful)
                {
                    return(Json(new List <NameValueObject> {
                        add
                    }, JsonRequestBehavior.AllowGet));
                }

                if (!retVal.Users.Any())
                {
                    return(Json(new List <NameValueObject> {
                        add
                    }, JsonRequestBehavior.AllowGet));
                }

                var sleIds = Session["_selUserIds_"] as List <int> ?? new List <int>();

                var parentTabs = retVal.Users.FindAll(m => !sleIds.Contains(m.UserId)).OrderBy(g => g.Email);
                add = new NameValueObject {
                    Id = 0, Name = "-- Select Item --"
                };

                var jsonitem = parentTabs.Select(o => new NameValueObject {
                    Id = o.UserId, Name = o.Email
                }).ToList();
                jsonitem.Insert(0, add);
                return(Json(jsonitem, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new List <NameValueObject> {
                    add
                }, JsonRequestBehavior.AllowGet));
            }
        }
Example #16
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            filterContext.Controller.ViewBag.IsSuccessful = false;
            filterContext.Controller.ViewBag.Error        = "";

            var modelList = filterContext.ActionParameters.Where(ap => ap.Key == "model").ToList();

            if (modelList.IsNullOrEmpty())
            {
                filterContext.Controller.ViewBag.Error = "Invalid Password Information";
                return;
            }
            if (!modelList.Any() || modelList.Count != 1)
            {
                filterContext.Controller.ViewBag.Error = "Invalid Password Information";
                return;
            }

            if (!(modelList[0].Value is ChangePasswordContract model))
            {
                filterContext.Controller.ViewBag.Error = "Invalid Password Information";
                return;
            }

            if (!GenericVal.Validate(model, out var msg))
            {
                filterContext.Controller.ViewBag.Error = msg;
                return;
            }

            if (
                string.Compare(model.OldPassword.Trim(), model.NewPassword.Trim(),
                               StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                model.ConfirmPassword = "";
                model.NewPassword     = "";
                model.OldPassword     = "";
                filterContext.Controller.ViewBag.Error = "Current Password and New Password cannot be same";
                return;
            }

            if (
                string.Compare(model.ConfirmPassword.Trim(), model.NewPassword.Trim(),
                               StringComparison.InvariantCultureIgnoreCase) != 0)
            {
                model.ConfirmPassword = "";
                model.NewPassword     = "";
                model.OldPassword     = "";
                filterContext.Controller.ViewBag.Error = "New Password and Confirm New Password must match";
                return;
            }

            var passObj = new ChangePasswordObj
            {
                NewPassword = model.NewPassword,
                OldPassword = model.OldPassword,
                UserId      = model.UserId,
                ChangeType  = (int)PasswordChangeType.Regular
            };

            var changePassword = new PortalUserManager().ChangePassword(passObj, model.Username);

            if (changePassword == null)
            {
                filterContext.Controller.ViewBag.Error = "Process Failed! Unable to change password";
                return;
            }
            if (!changePassword.Status.IsSuccessful)
            {
                filterContext.Controller.ViewBag.Error = string.IsNullOrEmpty(changePassword.Status.Message.FriendlyMessage) ? "Process Failed! Unable to change your password" : changePassword.Status.Message.FriendlyMessage;
                return;
            }


            filterContext.Controller.ViewBag.IsSuccessful = true;
            base.OnActionExecuting(filterContext);
        }
Example #17
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            filterContext.Controller.ViewBag.UserINFOCode   = null;
            filterContext.Controller.ViewBag.FirstLogin     = null;
            filterContext.Controller.ViewBag.EmailConfirmed = null;
            filterContext.Controller.ViewBag.Error          = "";


            var modelList = filterContext.ActionParameters.Where(ap => ap.Key == "model").ToList();

            if (modelList.IsNullOrEmpty() || !modelList.Any() || modelList.Count != 1)
            {
                filterContext.Controller.ViewBag.Error = "Invalid Login Information";
                return;
            }

            if (!(modelList[0].Value is UserLoginContract model))
            {
                filterContext.Controller.ViewBag.Error = "Invalid Login Information";
                return;
            }

            if (!GenericVal.Validate(model, out var msg))
            {
                filterContext.Controller.ViewBag.Error = msg;
                return;
            }

            if (string.IsNullOrEmpty(model.Username) || string.IsNullOrEmpty(model.Password) || model.Password.Length < 2)
            {
                model.Password = "";
                filterContext.ActionParameters["model"] = model;
                filterContext.Controller.ViewBag.Error  = "Empty / Invalid username or password or password length";
                return;
            }


            UserLoginRespObj user;

            try
            {
                var loginObj = new UserLoginObj
                {
                    Password      = model.Password,
                    Email         = model.Username,
                    LoginChannel  = (int)LoginChannel.Web,
                    SourceAddress = "192.168.17.25",
                };

                user = new PortalUserManager().Login(loginObj);
                if (user == null)
                {
                    model.Password = "";
                    filterContext.ActionParameters["model"] = model;
                    filterContext.Controller.ViewBag.Error  = "Login Failed! Please try again later";
                    return;
                }

                if (!user.Status.IsSuccessful)
                {
                    model.Password = "";
                    filterContext.ActionParameters["model"] = model;
                    filterContext.Controller.ViewBag.Error  = string.IsNullOrEmpty(user.Status.Message.FriendlyMessage)
                        ? "Login Failed!"
                        : user.Status.Message.FriendlyMessage;
                    if (!string.IsNullOrEmpty(user.Status.Message.MessageId) &&
                        user.Status.Message.MessageId.Length > 3)
                    {
                        if (user.Status.Message.MessageId == "1001")
                        {
                            filterContext.Controller.ViewBag.EmailConfirmed = false;
                        }
                    }
                    return;
                }

                if (user.UserItem == null || user.UserItem.UserId < 1)
                {
                    model.Password = "";
                    filterContext.ActionParameters["model"] = model;
                    filterContext.Controller.ViewBag.Error  = string.IsNullOrEmpty(user.Status.Message.FriendlyMessage)
                        ? "Login Failed!"
                        : user.Status.Message.FriendlyMessage;
                    return;
                }
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.GetBaseException().Message);
                model.Password = "";
                filterContext.ActionParameters["model"] = model;
                filterContext.Controller.ViewBag.Error  = "Error Occurred! Unable to complete your request";
                return;
            }

            //Check Multiple Login
            //Log user Out of previous login
            //Create new login
            var code = model.Username.Trim() + model.Password.Trim();

            if (MvcApplication.IsUserAlreadyLoggedIn(code, out _))
            {
                MvcApplication.ResetLogin(code);
                MvcApplication.ResetUserData(model.Username.Trim());
                filterContext.HttpContext.Session["UserINFO"] = null;
                new FormsAuthenticationService().SignOut();
            }

            var userId = user.UserItem.UserId;

            var clientProdList =
                ClientService.LoadClientProductList(new ClientProdSearchObj {
                AdminUserId = userId, UserId = userId
            },
                                                    model.Username.Trim()) ?? new ClientProdsRespObj();

            var userData = new UserData
            {
                UserId            = userId,
                Username          = user.UserItem.Email,
                Email             = user.UserItem.Email,
                Roles             = user.UserItem.RoleNames.ToArray(),
                UserType          = (UserType)user.UserItem.UserType,
                ClientProductList = clientProdList.ClientProductList ?? new List <ClientProductInfo>() //
            };

            if (!MvcApplication.SetPortalTabData(user.UserItem.TabItems, user.UserItem.Email))
            {
                model.Password = "";
                filterContext.ActionParameters["model"] = model;
                filterContext.Controller.ViewBag.Error  = "Invalid authentication!";
                return;
            }

            if (!MvcApplication.SetUserData(userData))
            {
                model.Password = "";
                filterContext.ActionParameters["model"] = model;
                filterContext.Controller.ViewBag.Error  = "Invalid authentication!";
                return;
            }

            var ticketData = userId + "|" + user.UserItem.UserType + "|" + string.Join(";", user.UserItem.RoleNames.ToArray());
            var encTicket  = new FormsAuthenticationService().SignIn(model.Username, false, ticketData);

            if (string.IsNullOrEmpty(encTicket))
            {
                model.Password = "";
                filterContext.ActionParameters["model"] = model;
                filterContext.Controller.ViewBag.Error  = "Invalid authentication!";
                return;
            }

            filterContext.HttpContext.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
            filterContext.Controller.ViewBag.UserINFOCode   = code.GetHashCode().ToString(CultureInfo.InvariantCulture);
            filterContext.Controller.ViewBag.FirstLogin     = user.UserItem.IsFirstTimeLogin;
            filterContext.Controller.ViewBag.EmailConfirmed = user.UserItem.IsEmailConfirmed;
            filterContext.Controller.ViewBag.LoginDataItem  = userData;
            base.OnActionExecuting(filterContext);
        }
        public JsonResult ProcessPasswordChangeRequest(string myOldPassword, string myNewPassword, string myConfirmPassword)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }
                if (string.IsNullOrEmpty(myOldPassword) || myOldPassword.Length < 3)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Old Password must be at least 3 characters" }));
                }

                if (string.IsNullOrEmpty(myNewPassword) || myNewPassword.Length < 3)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "New Password must be at least 3 characters" }));
                }

                if (string.IsNullOrEmpty(myConfirmPassword) || myConfirmPassword.Length < 3)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Confirm Password must be at least 3 characters" }));
                }

                if (string.Compare(myOldPassword, myNewPassword, StringComparison.CurrentCultureIgnoreCase) == 0)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "New Password must be different from the Old Password" }));
                }
                if (string.Compare(myConfirmPassword, myNewPassword, StringComparison.CurrentCultureIgnoreCase) != 0)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "New Password and Confirm Password must match" }));
                }

                var passObj = new ChangePasswordObj
                {
                    NewPassword = myNewPassword,
                    OldPassword = myOldPassword,
                    ChangeType  = (int)PasswordChangeType.Regular,
                    UserId      = userData.UserId,
                };


                var changePassword = new PortalUserManager().ChangePassword(passObj, userData.Username);
                if (changePassword == null || changePassword.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!changePassword.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(changePassword.Status.Message.FriendlyMessage) ? "Process Failed! Unable to change your password" : changePassword.Status.Message.FriendlyMessage }));
                }

                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
Example #19
0
        public ActionResult Index(int?clientId, int?productId)
        {
            try
            {
                ViewBag.Error = "";

                #region Client Product productItem Session Check

                var userClientSession = (AppSession)Session["_UserClientSession_"];
                if (userClientSession == null || userClientSession.ClientId < 1 || userClientSession.ProductId < 1 || userClientSession.ProductItemId < 1)
                {
                    return(RedirectToAction("Index", "Dashboard"));
                }
                var ClientId      = clientId ?? userClientSession.ClientId;
                var ProductId     = productId ?? userClientSession.ProductId;
                var ProductItemId = userClientSession.ProductItemId;

                #endregion

                #region Current User Session Check

                var userData = MvcApplication.GetUserData(User.Identity.Name);
                if (userData == null || userData.UserId < 1)
                {
                    ViewBag.Error = "Session Has Expired! Please Re-Login";
                    return(View(new List <DepartmentUserObj>()));
                }

                #endregion

                #region Check if Department User Session is null esle return to list

                if (Session["_DepartmentUserList_"] is List <DepartmentUserObj> DepartmentUser && DepartmentUser.Any())
                {
                    if (Session["_DepartmentList_"] is List <DepartmentObj> DepartmentList)
                    {
                        Session["_DepartmentList_"] = DepartmentList;
                    }
                    if (Session["_UsersList_"] is List <UserItemObj> UserList)
                    {
                        Session["_UsersList_"] = UserList;
                    }
                    var depList = DepartmentUser.Where(m => m.ClientId == ClientId && m.ProductId == ProductId).ToList();
                    return(View(depList));
                }

                #endregion

                #region Request Response and Validation of responses

                var searchObj2 = new UserSearchObj
                {
                    AdminUserId = userData.UserId,
                    Status      = -1000,
                    StopDate    = "",
                    StartDate   = "",
                    UserId      = 0,
                };
                var retValForUsers = new PortalUserManager().LoadUsers(searchObj2, userData.Username);

                if (retValForUsers?.Status == null)
                {
                    ViewBag.Error = "Error Occurred!";
                    return(View(new List <DepartmentUserObj>()));
                }

                if (retValForUsers.Users == null || !retValForUsers.Users.Any())
                {
                    ViewBag.Error = "Error Occurred!";
                    return(View(new List <DepartmentUserObj>()));
                }

                var searchObj3 = new DepartmentSearchObj
                {
                    AdminUserId  = userData.UserId,
                    DepartmentId = 0,
                    Status       = -1000,
                    StopDate     = "",
                    StartDate    = ""
                };
                var retValForDepartment = ExpenseLookUpServices.LoadDepartments(searchObj3, userData.Username);
                if (retValForDepartment?.Status == null)
                {
                    ViewBag.Error = "Error Occurred!";
                    return(View(new List <DepartmentUserObj>()));
                }

                if (retValForDepartment.Departments == null || !retValForDepartment.Departments.Any())
                {
                    ViewBag.Error = "Error Occurred!";
                    return(View(new List <DepartmentUserObj>()));
                }



                var searchObj = new DepartmentUserSearchObj
                {
                    AdminUserId      = userData.UserId,
                    DepartmentUserId = 0,
                };
                var retVal = DepartmentUserServices.LoadDepartmentUsers(searchObj, userData.Username);

                if (retVal?.Status == null)
                {
                    ViewBag.Error = " DepartmentUser list is empty!";
                    return(View(new List <DepartmentUserObj>()));
                }

                if (!retVal.Status.IsSuccessful)
                {
                    ViewBag.Error = string.IsNullOrEmpty(retVal.Status.Message.FriendlyMessage)
                        ? "  DepartmentUser list is empty!"
                        : retVal.Status.Message.FriendlyMessage;
                    return(View(new List <DepartmentUserObj>()));
                }
                if (retVal.DepartmentUsers == null || !retVal.DepartmentUsers.Any())
                {
                    ViewBag.Error = " DepartmentUser list is empty!";
                    return(View(new List <DepartmentUserObj>()));
                }


                #endregion

                #region Initialization of Responses into Sessions

                var Users           = retValForUsers.Users.OrderBy(m => m.UserId).ToList();
                var Depts           = retValForDepartment.Departments.OrderBy(m => m.DepartmentId).ToList();
                var DepartmentUsers = retVal.DepartmentUsers.OrderBy(m => m.DepartmentUserId).Where(m => m.ClientId == ClientId &&
                                                                                                    m.ProductId == ProductId).ToList();



                Session["_DepartmentUserList_"] = DepartmentUsers;
                Session["_DepartmentList_"]     = Depts.ToList();

                Session["_UsersList_"] = Users.ToList();

                #endregion

                return(View(DepartmentUsers));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new List <DepartmentUserObj>()));
            }
        }
Example #20
0
        public JsonResult ProcessAddUserRequest(PortalUserViewModel portalUser)
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();

                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                //var bearerAuth = MvcApplication.GetSessionBearerData(userData.Username);
                //var authToken = MvcApplication.GetSessionAuthData(userData.Username);

                //if (string.IsNullOrEmpty(bearerAuth) || bearerAuth.Length < 5)
                //{
                //    return Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid User Session! Please Re-Login" });
                //}

                //if (string.IsNullOrEmpty(authToken) || authToken.Length < 5)
                //{
                //    return Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid User Session! Please Re-Login" });
                //}

                if (portalUser == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Invalid Tab Item" }));
                }

                if (string.IsNullOrEmpty(portalUser.FirstName))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "First Name is required" }));
                }

                if (string.IsNullOrEmpty(portalUser.Email))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Email is required" }));
                }

                if (string.IsNullOrEmpty(portalUser.Password) || portalUser.Password.Length < 3)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Password is required" }));
                }

                if (string.IsNullOrEmpty(portalUser.ConfirmPassword) || portalUser.ConfirmPassword.Length < 3)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Password Confirmation is required" }));
                }

                if (string.Compare(portalUser.ConfirmPassword, portalUser.Password, StringComparison.CurrentCultureIgnoreCase) != 0)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Password and Password Confirmation must be equal" }));
                }

                if (portalUser.MyRoleIds == null || !portalUser.MyRoleIds.Any())
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Tab Roles are required" }));
                }

                if (!(Session["_portal_user_allroles"] is List <NameValueObject> allRoles) || !allRoles.Any())
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Your session has expired" }));
                }

                // var selRoles = allRoles.Where(m => portalUser.MyRoleIds.Contains(m.Id)).Select(m => m.Name).ToList();

                var passObj = new RegUserObj
                {
                    FirstName    = portalUser.FirstName,
                    LastName     = portalUser.LastName,
                    Password     = portalUser.Password,
                    Email        = portalUser.Email,
                    MobileNumber = portalUser.MobileNumber,
                    AdminUserId  = userData.UserId,
                    UserType     = 1,
                };


                var response = new PortalUserManager().AddUser(passObj, userData.Username);
                if (response == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }



                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.FriendlyMessage) ? "Process Failed! Unable to add user" : response.Status.Message.FriendlyMessage }));
                }


                if (response.UserId > 0)
                {
                    var userRole = new RegUserRoleObj
                    {
                        UserId      = response.UserId,
                        RoleIds     = string.Join(",", portalUser.MyRoleIds),
                        AdminUserId = userData.UserId,
                    };

                    var response2 = new PortalRoleManager().AdUserToRole(userRole, userData.Username);


                    if (!response2.Status.IsSuccessful)
                    {
                        return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.FriendlyMessage) ? "User information was added but user roles not added" : "User information was added but role Error: " + response.Status.Message.FriendlyMessage + " occured!" }));
                    }
                }


                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
Example #21
0
        public JsonResult ProcessEditDepartmentUserRequest(DepartmentUserObj model)
        {
            try
            {
                #region Current User Session Check

                var userData = MvcApplication.GetUserData(User.Identity.Name) ?? new UserData();
                if (userData.UserId < 1)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                #endregion

                #region Model Validation

                if (model == null)
                {
                    return(Json(new { IsSuccessful = false, Error = "Your session has expired", IsAuthenticated = false }));
                }

                if (model.ClientId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "client required " }));
                }
                if (model.DepartmentUserId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Department User Id required " }));
                }

                if (model.ProductItemId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Product Item required " }));
                }

                if (model.ProductId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Product required " }));
                }
                if (model.DepartmentId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "Department  required " }));
                }
                if (model.UserId < 1)
                {
                    return(Json(new { isauthenticated = true, issuccessful = false, isreload = false, error = "User required " }));
                }
                if (!GenericVal.Validate(model, out var msg))
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = $"Validation Error Occurred! Detail: {msg}" }));
                }
                #endregion

                #region Check if Item Already Exist

                var previousDepartmentList = (List <DepartmentUserObj>)Session["_DepartmentUserList_"];
                if (previousDepartmentList != null)
                {
                    if (previousDepartmentList.Count(x => x.DepartmentId == model.DepartmentId &&
                                                     x.ClientId == model.ClientId &&
                                                     x.ProductId == model.ProductId &&
                                                     x.ProductItemId == model.ProductItemId &&
                                                     x.UserId == model.UserId &&
                                                     x.DepartmentUserId != x.DepartmentUserId) > 0)
                    {
                        return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "User Already Added to Department" }));
                    }
                }

                #endregion

                #region Request from Users Service

                var searchObj2 = new UserSearchObj
                {
                    AdminUserId = userData.UserId,
                    Status      = -2,
                    StopDate    = "",
                    StartDate   = "",
                    UserId      = 0,
                };

                var userRetVal = new PortalUserManager().LoadUsers(searchObj2, userData.Username);

                if (userRetVal?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                var userList = userRetVal.Users.OrderBy(x => x.UserId).ToList();

                #endregion


                var previousDepartmentUserList = (List <DepartmentUserObj>)Session["_DepartmentUserList_"];

                #region Build Request


                var passObj = new EditDepartmentUserObj()
                {
                    ClientId         = model.ClientId,
                    ProductId        = model.ProductId,
                    AdminUserId      = userData.UserId,
                    Status           = 1,
                    ProductItemId    = model.ProductItemId,
                    DepartmentId     = model.DepartmentId,
                    UserId           = model.UserId,
                    UserRoles        = string.Join(",", userList.FirstOrDefault(x => x.UserId == model.UserId).RoleNames),
                    Email            = userList.FirstOrDefault(x => x.UserId == model.UserId).Email,
                    FullName         = userList.FirstOrDefault(x => x.UserId == model.UserId).FirstName + " " + userList.FirstOrDefault(x => x.UserId == model.UserId).LastName,
                    DepartmentUserId = model.DepartmentUserId
                };


                #endregion

                #region Request and Response Validations

                var response = DepartmentUserServices.UpdateDepartmentUser(passObj, userData.Username);
                if (response?.Status == null)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Error Occurred! Please try again later" }));
                }

                if (!response.Status.IsSuccessful)
                {
                    return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = string.IsNullOrEmpty(response.Status.Message.TechnicalMessage) ? "Process Failed! Unable to add course of study" : response.Status.Message.TechnicalMessage }));
                }

                Session["_CurrentSelDepartmentUser_"] = null;

                var searchObj = new DepartmentUserSearchObj
                {
                    AdminUserId      = userData.UserId,
                    DepartmentUserId = 0,
                    Status           = -2
                };

                var retVal = DepartmentUserServices.LoadDepartmentUsers(searchObj, userData.Username);
                if (retVal?.Status != null && retVal.DepartmentUsers != null)
                {
                    var DepartmentUsers = retVal.DepartmentUsers.OrderBy(m => m.DepartmentUserId).ToList();
                    Session["_DepartmentUserList_"] = DepartmentUsers.Where(m => m.ClientId == model.ClientId && m.ProductId == model.ProductItemId && m.ProductItemId == model.ProductItemId).ToList();
                }

                #endregion



                return(Json(new { IsAuthenticated = true, IsSuccessful = true, IsReload = false, Error = "" }));
            }
            catch (Exception ex)
            {
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(Json(new { IsAuthenticated = true, IsSuccessful = false, IsReload = false, Error = "Process Error Occurred! Please try again later" }));
            }
        }
Example #22
0
        public ActionResult Index()
        {
            try
            {
                var userData = MvcApplication.GetUserData(User.Identity.Name);
                if (userData == null || userData.UserId < 1)
                {
                    ViewBag.Error = "Session Has Expired! Please Re-Login";
                    return(View(new List <UserItemObj>()));
                }

                //var bearerAuth = MvcApplication.GetSessionBearerData(userData.Username);
                //var authToken = MvcApplication.GetSessionAuthData(userData.Username);

                var searchObj = new RoleSearchObj
                {
                    AdminUserId = userData.UserId,
                    RoleId      = 0,
                    Status      = -2,
                };

                var roleVal = new PortalRoleManager().LoadRoles(searchObj, userData.Username);
                if (roleVal?.Status == null)
                {
                    ViewBag.Error = "Role Item list is empty! Roles must be defined before setting up users";
                    return(View(new List <UserItemObj>()));
                }



                if (!roleVal.Status.IsSuccessful)
                {
                    ViewBag.Error = string.IsNullOrEmpty(roleVal.Status.Message.FriendlyMessage)
                        ? "Role Item list is empty! Roles must be defined before setting up users"
                        : roleVal.Status.Message.FriendlyMessage;
                    return(View(new List <UserItemObj>()));
                }

                if (roleVal.Roles == null)
                {
                    ViewBag.Error = "Role Item list is empty! Roles must be defined before setting up users";
                    return(View(new List <UserItemObj>()));
                }

                var roles = roleVal.Roles.Where(m => m.Status == 1).ToList();
                if (!roles.Any())
                {
                    ViewBag.Error = "Role Item list is empty! Roles must be defined before setting up users";
                    return(View(new List <UserItemObj>()));
                }

                var allRoles = new List <NameValueObject>();

                foreach (var item in roles)
                {
                    allRoles.Add(new NameValueObject
                    {
                        Id   = item.RoleId,
                        Name = item.Name
                    });
                }

                Session["_portal_user_allroles"] = allRoles;

                var searchObj2 = new UserSearchObj
                {
                    AdminUserId = userData.UserId,
                    Status      = -2,
                    StopDate    = "",
                    StartDate   = "",
                    UserId      = 0,
                };

                var retVal = new PortalUserManager().LoadUsers(searchObj2, userData.Username);
                if (retVal?.Status == null)
                {
                    ViewBag.Error = "Portal User list is empty!";
                    return(View(new List <UserItemObj>()));
                }

                if (!retVal.Status.IsSuccessful)
                {
                    ViewBag.Error = string.IsNullOrEmpty(retVal.Status.Message.FriendlyMessage)
                        ? "Portal User list is empty!"
                        : retVal.Status.Message.FriendlyMessage;
                    return(View(new List <UserItemObj>()));
                }
                if (!retVal.Users.Any())
                {
                    ViewBag.Error = "Portal User list is empty!";
                    return(View(new List <UserItemObj>()));
                }

                var allUsers = retVal.Users.OrderBy(m => m.UserId).ToList();
                Session["_portalUsers"] = allUsers;
                return(View(allUsers));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new List <UserItemObj>()));
            }
        }