Esempio n. 1
0
        public ResponseModel UpdateEmployee(PortalUserViewModel model)
        {
            var errMessage     = string.Empty;
            var queryParamList = new QueryParamList
            {
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@Id", ParamValue = model.Id
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@UserFullName", ParamValue = model.UserFullName
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@DesignationName", ParamValue = model.DesignationName
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@ImageFileName", ParamValue = model.ImageFileName
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@ImageFileId", ParamValue = model.ImageFileId
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@IsActive", ParamValue = model.IsActive
                },
            };

            const string sql = @"UPDATE ResourceTracker_EmployeeUser SET UserName=@UserFullName,Designation=@DesignationName,
                                ImageFileName=@ImageFileName,ImageFileId=@ImageFileId,IsActive=@IsActive WHERE Id=@Id";

            DBExecCommandEx(sql, queryParamList, ref errMessage);

            return(new ResponseModel {
                Success = string.IsNullOrEmpty(errMessage)
            });
        }
Esempio n. 2
0
        public ActionResult _AddUser()
        {
            try
            {
                ViewBag.Error = "";
                var userModel = new PortalUserViewModel {
                    AllRoles = new List <NameValueObject>(), MyRoleIds = new[] { 0 }
                };

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

                if (!(Session["_portal_user_allroles"] is List <NameValueObject> allRoles) || !allRoles.Any())
                {
                    ViewBag.Error = "Session Has Expired! Please Re-Login";
                    return(View(userModel));
                }

                userModel.AllRoles = allRoles;
                //Use this to check it its admin user
                userModel.UserId = userData.UserId == 1 ? 1 : 0;
                return(View(userModel));
            }
            catch (Exception ex)
            {
                ViewBag.Error = "Error Occurred! Please try again later";
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new PortalUserViewModel()));
            }
        }
Esempio n. 3
0
        //GET: Portals/Details/5
        public ActionResult Details(Guid id)
        {
            ViewBag.Data = id;
            var UserId     = User.Identity.GetUserId();
            var portal     = _context.Portals.SingleOrDefault(p => p.Id == id);
            var @portals   = _context.PortalUsers.Where(c => c.UserId == UserId).Select(x => x.Portal).ToList();
            var Authorised = @portals.Contains(portal);

            if (Authorised)
            {
                var ViewModel = new PortalUserViewModel();
                ViewModel.Portal = portal;
                ViewModel.UserID = id;
                var PortalCases = (from x in _context.Cases where x.PortalId == id select x).ToList();
                ViewModel.PortalCases = PortalCases;
                return(View("PortalForm", ViewModel));
            }
            else
            {
                return(Content("Sorry not Authorised to View!"));
            }
        }
Esempio n. 4
0
        public IHttpActionResult UpdateEmployee(PortalUserViewModel json)
        {
            var response = _employeeRepository.UpdateEmployee(json);

            return(Ok(response));
        }
Esempio n. 5
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" }));
            }
        }
Esempio n. 6
0
        public ActionResult _EditUser(int userId)
        {
            try
            {
                var userModel = new PortalUserViewModel {
                    AllRoles = new List <NameValueObject>(), MyRoleIds = new[] { 0 }
                };
                ViewBag.Error = "";
                if (userId < 1)
                {
                    ViewBag.Error = "Invalid selection";
                    return(View(userModel));
                }

                if (!(Session["_portalUsers"] is List <UserItemObj> userList) || userList.Count < 1)
                {
                    ViewBag.Error = "Error Occurred! Unable to prepare this portal tab information for modification";
                    return(View(userModel));
                }

                var thisUser = userList.Find(m => m.UserId == userId);
                if (thisUser == null || thisUser.UserId < 1)
                {
                    ViewBag.Error = "Error Occurred! Unable to prepare this portal user information for modification";
                    return(View(userModel));
                }

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

                if (!(Session["_portal_user_allroles"] is List <NameValueObject> allRoles) || !allRoles.Any())
                {
                    ViewBag.Error = "Session Has Expired! Please Re-Login";
                    return(View(userModel));
                }

                userModel.AllRoles = allRoles;
                var rolesId      = new List <int>();
                var splitedRoles = thisUser.RoleNames; //.Select(m => m.Name).ToArray();
                foreach (var item in allRoles)
                {
                    if (splitedRoles.Contains(item.Name))
                    {
                        rolesId.Add(item.Id);
                    }
                }

                userModel.Username     = thisUser.Email;
                userModel.UserId       = thisUser.UserId;
                userModel.Email        = thisUser.Email;
                userModel.FirstName    = thisUser.FirstName;
                userModel.LastName     = thisUser.LastName;
                userModel.MobileNumber = thisUser.MobileNumber;
                userModel.IsApproved   = ((UserStatus)thisUser.Status) == UserStatus.Active;
                userModel.MyRoleIds    = rolesId.ToArray();

                //Use this to check it its admin user
                userModel.UserId = userData.UserId == 1 ? 1 : 0;


                return(View(userModel));
            }
            catch (Exception ex)
            {
                ViewBag.Error = "Error Occurred! Please try again later";
                UtilTools.LogE(ex.StackTrace, ex.Source, ex.Message);
                return(View(new PortalUserViewModel()));
            }
        }
Esempio n. 7
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" }));
            }
        }