public string UpdateUserPages(UserPagesVM userPage)
        {
            string userPageId = string.Empty;

            SqlParameter[] parameters =
            {
                new SqlParameter {
                    ParameterName = "@Id", Value = userPage.Id
                },
                new SqlParameter {
                    ParameterName = "@UserId", Value = userPage.UserId
                },
                new SqlParameter {
                    ParameterName = "@PageId", Value = userPage.PageId
                },
                new SqlParameter {
                    ParameterName = "@IsAdd", Value = userPage.IsAdd
                },
                new SqlParameter {
                    ParameterName = "@IsEdit", Value = userPage.IsEdit
                },
                new SqlParameter {
                    ParameterName = "@IsDelete", Value = userPage.IsDelete
                },
                new SqlParameter {
                    ParameterName = "@IsView", Value = userPage.IsView
                },
                new SqlParameter {
                    ParameterName = "@Description", Value = userPage.Description
                },
                new SqlParameter {
                    ParameterName = "@IsActive", Value = userPage.IsActive
                },
                new SqlParameter {
                    ParameterName = "@UpdatedBy", Value = userPage.UpdatedBy
                }
            };

            userPageId = Convert.ToString(DALHelper.ExecuteScalar("UpdateUserPages", parameters));

            return(userPageId);
        }
Beispiel #2
0
        public ActionResult Register(UserVM model)
        {
            try
            {
                #region Get Student Role Id

                var userRoles     = userRoleRepository.GetUserRoles();
                var studentRoleId = userRoles.Where(m => m.Code == "STUDENT").FirstOrDefault().Id;

                #endregion

                //Check Email Exist.
                #region Check User Email Exist

                if (this.CheckUserEmailExist(model.Id, studentRoleId, model.Email) == true)
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        errorMessage = string.Format("Email : {0} already registered.", model.Email)
                    }, JsonRequestBehavior.AllowGet));
                }

                #endregion

                #region Max. User Id

                //Get Max. User Id.
                var newUserId = (userRepository.GetMaxUserId()) + 1;
                model.UserId = newUserId;

                #endregion

                #region Generate Cashier Number

                var firstTwoCharactersOfName = !string.IsNullOrWhiteSpace(model.Name) ? model.Name.Substring(0, 2) : "";
                model.CashierNumber = (firstTwoCharactersOfName + newUserId).ToUpper();

                #endregion Generate Cashier Number

                #region Generate New Password

                //Generate new password.
                string newPassword = Utility.Utility.GenerateRandomPassword(8);
                model.Password = Utility.Utility.Encrypt(newPassword, Utility.Utility.EncryptionKey);

                #endregion

                #region Get Admin User Id

                int createdBy = 0;

                var adminRoleId = userRoles.Where(m => m.Code == "ADMIN").FirstOrDefault().Id;
                var adminUser   = userRepository.GetUserDetailByRoleId(adminRoleId).FirstOrDefault();

                if (adminUser != null)
                {
                    createdBy = adminUser.UserId;
                }

                #endregion

                string userId = string.Empty;
                model.CreatedBy = createdBy;

                model.IsActive               = false;
                model.IsRecordActivity       = true;
                model.IsFromRegistrationPage = true;

                userId = userRepository.AddUserDetail(model);

                if (!string.IsNullOrWhiteSpace(userId))
                {
                    #region Add User Role Mapping

                    UserRoleMappingVM userRoleMapping = new UserRoleMappingVM();
                    userRoleMapping.UserId     = Guid.Parse(userId);
                    userRoleMapping.UserRoleId = studentRoleId;
                    userRoleMapping.IsActive   = true;
                    userRoleMapping.CreatedBy  = createdBy;
                    userRoleMapping.UpdatedBy  = createdBy;

                    userRepository.AddUpdateUserRoleMapping(userRoleMapping);

                    #endregion

                    #region Add User Page Access Rights For Profile Page

                    var profilePage = pageRepository.GetPageDetailByPageCode("INDIVIDUALPROFILE").FirstOrDefault();

                    if (profilePage != null)
                    {
                        UserPagesVM userPage = new UserPagesVM();
                        userPage.UserId = Guid.Parse(userId);
                        userPage.PageId = profilePage.Id;
                        if (model.IsAllowToDeleteProfile)
                        {
                            userPage.IsDelete = true;
                        }
                        else
                        {
                            userPage.IsDelete = false;
                        }
                        userPage.IsAdd     = true;
                        userPage.IsEdit    = true;
                        userPage.IsView    = true;
                        userPage.IsActive  = true;
                        userPage.CreatedBy = createdBy;

                        userPageRepository.AddUserPages(userPage);
                    }

                    #endregion

                    #region Add Tutor Student Mapping

                    TutorStudentMappingVM tutorStudentMapping = new TutorStudentMappingVM();
                    tutorStudentMapping.TutorId   = model.TutorId.Value;
                    tutorStudentMapping.StudentId = Guid.Parse(userId);
                    tutorStudentMapping.UserId    = newUserId;
                    tutorStudentMapping.CreatedBy = createdBy;
                    tutorStudentMapping.UpdatedBy = createdBy;
                    tutorStudentMapping.IsActive  = true;

                    userRepository.AddUpdateTutorStudentMapping(tutorStudentMapping);

                    #endregion

                    return(Json(new
                    {
                        IsSuccess = true,
                        data = new
                        {
                            UserId = userId
                        }
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        errorMessage = "You have not registered successfully. Something went wrong!"
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                Utility.Utility.LogError(e, "Register POST");

                return(Json(new
                {
                    IsSuccess = false,
                    errorMessage = e.Message
                }));
            }
        }
        public ActionResult Create(UserVM model)
        {
            try
            {
                string userId = string.Empty;
                model.CreatedBy = LogInManager.LoggedInUserId;
                model.Password  = Utility.Utility.Encrypt(model.Password, Utility.Utility.EncryptionKey);

                #region Get Student Role Id

                var userRoles     = userRoleRepository.GetUserRoles();
                var studentRoleId = userRoles.Where(m => m.Code == "STUDENT").FirstOrDefault().Id;
                model.UserRoleId = studentRoleId;

                #endregion

                #region Check User Email Exist.

                if (this.CheckUserEmailExist(model.Id, model.UserRoleId, model.Email) == false)
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        errorMessage = string.Format("Email : {0} already exist.", model.Email)
                    }, JsonRequestBehavior.AllowGet));
                }

                #endregion

                #region Get Max. User Id

                //Get Max. User Id.
                var newUserId = (userRepository.GetMaxUserId()) + 1;
                model.UserId = newUserId;

                #endregion

                #region Generate Cashier Number

                var firstTwoCharactersOfName = !string.IsNullOrWhiteSpace(model.Name) ? model.Name.Substring(0, 2) : "";
                model.CashierNumber = (firstTwoCharactersOfName + newUserId).ToUpper();

                #endregion Generate Cashier Number

                model.IsFromRegistrationPage = false;

                userId = userRepository.AddUserDetail(model);

                if (!string.IsNullOrWhiteSpace(userId))
                {
                    #region Add User Role Mapping

                    UserRoleMappingVM userRoleMapping = new UserRoleMappingVM();
                    userRoleMapping.UserId     = Guid.Parse(userId);
                    userRoleMapping.UserRoleId = model.UserRoleId;
                    userRoleMapping.IsActive   = true;
                    userRoleMapping.CreatedBy  = LogInManager.LoggedInUserId;
                    userRoleMapping.UpdatedBy  = LogInManager.LoggedInUserId;


                    userRepository.AddUpdateUserRoleMapping(userRoleMapping);

                    #endregion

                    #region Add User Page Access Rights For Profile

                    var profilePage = pageRepository.GetPageDetailByPageCode("INDIVIDUALPROFILE").FirstOrDefault();

                    if (profilePage != null)
                    {
                        UserPagesVM userPage = new UserPagesVM();
                        userPage.UserId = Guid.Parse(userId);
                        userPage.PageId = profilePage.Id;
                        if (model.IsAllowToDeleteProfile)
                        {
                            userPage.IsDelete = true;
                        }
                        else
                        {
                            userPage.IsDelete = false;
                        }
                        userPage.IsAdd     = true;
                        userPage.IsEdit    = true;
                        userPage.IsView    = true;
                        userPage.IsActive  = true;
                        userPage.CreatedBy = LogInManager.LoggedInUserId;

                        userPageRepository.AddUserPages(userPage);
                    }


                    #endregion

                    #region Add Tutor Student Mapping

                    TutorStudentMappingVM tutorStudentMapping = new TutorStudentMappingVM();
                    tutorStudentMapping.TutorId   = model.TutorId.Value;
                    tutorStudentMapping.StudentId = Guid.Parse(userId);
                    tutorStudentMapping.UserId    = newUserId;
                    tutorStudentMapping.CreatedBy = LogInManager.LoggedInUserId;
                    tutorStudentMapping.UpdatedBy = LogInManager.LoggedInUserId;
                    tutorStudentMapping.IsActive  = true;

                    userRepository.AddUpdateTutorStudentMapping(tutorStudentMapping);

                    #endregion

                    return(Json(new
                    {
                        IsSuccess = true,
                        data = new
                        {
                            UserId = userId
                        }
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        errorMessage = "Student details not saved successfully."
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                Utility.Utility.LogError(e, "Create");
                return(Json(new
                {
                    IsSuccess = false,
                    errorMessage = e.Message
                }));
            }
        }
        public ActionResult Edit(UserVM model)
        {
            try
            {
                string userId = string.Empty;
                model.UpdatedBy = LogInManager.LoggedInUserId;

                #region Get Student Role Id

                var userRoles     = userRoleRepository.GetUserRoles();
                var studentRoleId = userRoles.Where(m => m.Code == "STUDENT").FirstOrDefault().Id;
                model.UserRoleId = studentRoleId;

                #endregion

                #region Check User Email Exist.

                if (this.CheckUserEmailExist(model.Id, model.UserRoleId, model.Email) == false)
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        errorMessage = string.Format("Email : {0} already exist.", model.Email)
                    }, JsonRequestBehavior.AllowGet));
                }

                #endregion

                #region Check Cashier Number Exist.

                if (!string.IsNullOrWhiteSpace(model.CashierNumber))
                {
                    if (this.CheckCashierNumberExist(model.Id, model.CashierNumber) == false)
                    {
                        return(Json(new
                        {
                            IsSuccess = false,
                            errorMessage = string.Format("Cashier Number : {0} already exist.", model.Email)
                        }, JsonRequestBehavior.AllowGet));
                    }
                }

                #endregion

                userId = userRepository.UpdateUserDetail(model);

                if (!string.IsNullOrWhiteSpace(userId))
                {
                    #region Add / Update User Role Mapping

                    UserRoleMappingVM userRoleMapping = new UserRoleMappingVM();
                    userRoleMapping.UserId     = Guid.Parse(userId);
                    userRoleMapping.UserRoleId = model.UserRoleId;
                    userRoleMapping.IsActive   = true;
                    userRoleMapping.CreatedBy  = LogInManager.LoggedInUserId;
                    userRoleMapping.UpdatedBy  = LogInManager.LoggedInUserId;

                    userRepository.AddUpdateUserRoleMapping(userRoleMapping);

                    #endregion

                    #region Add/Update User Page Access Rights For Profile

                    var profilePage = pageRepository.GetPageDetailByPageCode("INDIVIDUALPROFILE").FirstOrDefault();

                    var profilePageAccessRights = userPageRepository.GetUserPageAccessRights(Guid.Parse(userId), "INDIVIDUALPROFILE").FirstOrDefault();

                    if (profilePage != null)
                    {
                        UserPagesVM userPage = new UserPagesVM();
                        userPage.UserId = Guid.Parse(userId);
                        userPage.PageId = profilePage.Id;
                        if (model.IsAllowToDeleteProfile)
                        {
                            userPage.IsDelete = true;
                        }
                        else
                        {
                            userPage.IsDelete = false;
                        }
                        userPage.IsAdd     = true;
                        userPage.IsEdit    = true;
                        userPage.IsView    = true;
                        userPage.IsActive  = true;
                        userPage.CreatedBy = LogInManager.LoggedInUserId;
                        userPage.UpdatedBy = LogInManager.LoggedInUserId;

                        if (profilePageAccessRights == null)
                        {
                            userPageRepository.AddUserPages(userPage);
                        }
                        else
                        {
                            userPage.Id = profilePageAccessRights.Id;
                            userPageRepository.AddUserPages(userPage);
                        }
                    }



                    #endregion

                    #region Add/Update Tutor Student Mapping

                    TutorStudentMappingVM tutorStudentMapping = new TutorStudentMappingVM();
                    tutorStudentMapping.TutorId   = model.TutorId.Value;
                    tutorStudentMapping.StudentId = Guid.Parse(userId);
                    tutorStudentMapping.UserId    = model.UserId;
                    tutorStudentMapping.CreatedBy = LogInManager.LoggedInUserId;
                    tutorStudentMapping.UpdatedBy = LogInManager.LoggedInUserId;
                    tutorStudentMapping.IsActive  = true;

                    userRepository.AddUpdateTutorStudentMapping(tutorStudentMapping);

                    #endregion

                    return(Json(new
                    {
                        IsSuccess = true,
                        data = new
                        {
                            UserId = userId
                        }
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        errorMessage = "Student details not updated successfully."
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                Utility.Utility.LogError(e, "Edit");
                return(Json(new
                {
                    IsSuccess = false,
                    errorMessage = e.Message
                }));
            }
        }