/// <summary> /// Action to open user in edit mode /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult CreateUser(string id = "0") { try { User objUserinfo = new User(); int nUserId = Methods.doInt(Methods.base64Decode(id)); var nRecord = new GHC_UsersData(); if (nUserId > 0) { // GET USER INFORMATION DataRow dr = objDBGHC_Users.GHC_Users_GetAllById(nUserId); if (dr != null) { nRecord.nUserID = Methods.doLong(dr["nUserID"]); nRecord.sFirstName = Methods.CorrectDBNull(dr["sFirstName"]); nRecord.sLastName = Methods.CorrectDBNull(dr["sLastName"]); nRecord.sEmail = Methods.CorrectDBNull(dr["sEmail"]); nRecord.sPassword = Methods.CorrectDBNull(dr["sPassword"]); nRecord.sCity = Methods.CorrectDBNull(dr["sCity"]); nRecord.nStateID = Methods.doInt(dr["nStateID"]); nRecord.sZipCode = Methods.CorrectDBNull(dr["sZipCode"]); nRecord.nCountryID = Methods.doInt(dr["nCountryID"]); nRecord.bIsActive = Methods.doBoolean(dr["bIsActive"]); nRecord.sUserType = Methods.CorrectDBNull(dr["sUserType"]); } objUserinfo.objGHC_UsersData = nRecord; } return View(objUserinfo); } catch (Exception ex) { CommonRepository.LogError(sController, "CreateUser", ex.ToString()); Session[Helpers.CommonConstants.Message] = Messages.GetMessage("[Error]"); Session[Helpers.CommonConstants.MessageType] = "2"; return RedirectToAction("viewusers"); } }
public int GHC_Users_Update(GHC_UsersData objGHC_Users) { int rowsAffected = 0; SqlConnection connection = null; try { connection = (SqlConnection)new DBConnect().ConnectionObject; SqlCommand Command = new SqlCommand("GHC_GHC_Users_Update", connection); Command.CommandType = CommandType.StoredProcedure; Command.Parameters.AddWithValue("@nUserID", objGHC_Users.nUserID); Command.Parameters.AddWithValue("@sFirstName", objGHC_Users.sFirstName); Command.Parameters.AddWithValue("@sLastName", objGHC_Users.sLastName); Command.Parameters.AddWithValue("@sEmail", objGHC_Users.sEmail); Command.Parameters.AddWithValue("@sPassword", objGHC_Users.sPassword); Command.Parameters.AddWithValue("@sCity", objGHC_Users.sCity); Command.Parameters.AddWithValue("@nStateID", objGHC_Users.nStateID); Command.Parameters.AddWithValue("@sZipCode", objGHC_Users.sZipCode); Command.Parameters.AddWithValue("@nCountryID", objGHC_Users.nCountryID); Command.Parameters.AddWithValue("@sUserType", objGHC_Users.sUserType); Command.Parameters.AddWithValue("@bIsActive", objGHC_Users.bIsActive); Command.Parameters.AddWithValue("@dDateModified", objGHC_Users.dDateModified); Command.Parameters.AddWithValue("@nModifiedBy", objGHC_Users.nModifiedBy); SqlParameter returnValueParam = new SqlParameter("@RETURN_VALUE", SqlDbType.Int); returnValueParam.Direction = ParameterDirection.ReturnValue; Command.Parameters.Add(returnValueParam); connection.Open(); Command.ExecuteNonQuery(); rowsAffected = Convert.ToInt32(returnValueParam.Value); } catch { rowsAffected = 0; } finally { if (connection != null) connection.Close(); connection.Dispose(); } return rowsAffected; }
public ActionResult CreateUser(User objUsers, FormCollection form) { try { if (!ModelState.IsValid) { var sErrors = (from s in ModelState where s.Value.Errors.Count > 0 select s.Value.Errors).ToList(); string sErrorMsg = string.Empty; foreach (var obj in sErrors) obj.ToList().ForEach(a => sErrorMsg += "<br/>" + a.ErrorMessage); Session[Helpers.CommonConstants.Message] = sErrorMsg.Remove(0, 5); Session[Helpers.CommonConstants.MessageType] = "2"; return RedirectToAction("CreateUser"); } int nReturn = 0; int nUserId = Methods.doInt(form["hdnUserID"]); bool chkbIsActive = Methods.doBoolean(form.GetValues("chkbIsActive")[0]); objUsers.objGHC_UsersData.bIsActive = chkbIsActive; if (nUserId == 0) { //objUsers.objGHC_UsersData.dDateAdded = DateTime.Now; objUsers.objGHC_UsersData.dDateModified = DateTime.Now; objUsers.objGHC_UsersData.sPassword = (Methods.CorrectDBNull(objUsers.objGHC_UsersData.sPassword) != "") ? Methods.Encryption(objUsers.objGHC_UsersData.sPassword) : ""; // Add User GHC_UsersData objAddUser = new GHC_UsersData(); objAddUser.sFirstName = Methods.doInsertable(objUsers.objGHC_UsersData.sFirstName); objAddUser.sLastName = Methods.doInsertable(objUsers.objGHC_UsersData.sLastName); objAddUser.sEmail = Methods.doInsertable(objUsers.objGHC_UsersData.sEmail); objAddUser.sPassword = Methods.doInsertable(objUsers.objGHC_UsersData.sPassword); objAddUser.sCity = Methods.doInsertable(objUsers.objGHC_UsersData.sCity); objAddUser.sZipCode = Methods.doInsertable(objUsers.objGHC_UsersData.sZipCode); objAddUser.nStateID = Methods.doInt(objUsers.objGHC_UsersData.nStateID); objAddUser.nCountryID = Methods.doInt(objUsers.objGHC_UsersData.nCountryID); objAddUser.bIsActive = Methods.doBoolean(objUsers.objGHC_UsersData.bIsActive); objAddUser.sUserType = Methods.doInsertable(objUsers.objGHC_UsersData.sUserType); objAddUser.dDateAdded = DateTime.Now; objAddUser.nModifiedBy = Methods.doLong(Session[CommonConstants.LoggedInUserID]); nReturn = objDBGHC_Users.GHC_Users_Insert(objAddUser); //nReturn = objUserRepository.CreateUser(objUsers.objUser); if (nReturn > 1) { Session[Helpers.CommonConstants.Message] = Messages.GetMessage("[Insert]", "User"); Session[Helpers.CommonConstants.MessageType] = "1"; return RedirectToAction("viewusers"); } else if (nReturn == 2) { Session[Helpers.CommonConstants.Message] = Messages.GetMessage("[Exists]", "Email"); Session[Helpers.CommonConstants.MessageType] = "1"; } else { throw new Exception(); } } else { // Edit User objUsers.objGHC_UsersData.nUserID = nUserId; //objUsers.objGHC_UsersData.sPassword = (Methods.CorrectDBNull(objUsers.objGHC_UsersData.sPassword) != "") ? Methods.Encryption(objUsers.objGHC_UsersData.sPassword) : ""; objUsers.objGHC_UsersData.dDateModified = DateTime.Now; objUsers.objGHC_UsersData.nModifiedBy = Methods.nUserID; GHC_UsersData objUpdateUser = new GHC_UsersData(); int nUpdateruserID = Convert.ToInt32(Request.Form["hdnUserID"]); objUsers.objGHC_UsersData.sPassword = objUsers.objGHC_UsersData.sPassword; objUpdateUser.nUserID = nUpdateruserID; objUpdateUser.sFirstName = Methods.doInsertable(objUsers.objGHC_UsersData.sFirstName); objUpdateUser.sLastName = Methods.doInsertable(objUsers.objGHC_UsersData.sLastName); objUpdateUser.sEmail = Methods.doInsertable(objUsers.objGHC_UsersData.sEmail); objUpdateUser.sPassword = (Methods.CorrectDBNull(objUsers.objGHC_UsersData.sPassword) != "") ? Methods.Encryption(objUsers.objGHC_UsersData.sPassword) : ""; objUpdateUser.sCity = Methods.doInsertable(objUsers.objGHC_UsersData.sCity); objUpdateUser.nStateID = Methods.doInt(objUsers.objGHC_UsersData.nStateID); objUpdateUser.sZipCode = Methods.doInsertable(objUsers.objGHC_UsersData.sZipCode); objUpdateUser.nCountryID = Methods.doInt(objUsers.objGHC_UsersData.nCountryID); objUpdateUser.bIsActive = Methods.doBoolean(objUsers.objGHC_UsersData.bIsActive); objUpdateUser.dDateModified = DateTime.Now; objUpdateUser.nModifiedBy = Methods.doLong(Session[CommonConstants.LoggedInUserID]); objUpdateUser.sUserType = Methods.doInsertable(objUsers.objGHC_UsersData.sUserType); nReturn = objDBGHC_Users.GHC_Users_Update(objUpdateUser); //nReturn = objUserRepository.EditUser(objUsers.objUser); if (nReturn > 0) { Session[Helpers.CommonConstants.Message] = Messages.GetMessage("[Update]", "User"); Session[Helpers.CommonConstants.MessageType] = "1"; bool bAdminuser = Methods.doBoolean(Session[Helpers.CommonConstants.LoggedIsAdminUser]); if (bAdminuser) { return RedirectToAction("viewusers"); } else { return RedirectToAction("Index","Dashboard"); } } else if (nReturn == -1) { Session[Helpers.CommonConstants.Message] = Messages.GetMessage("[Exists]", "Email"); Session[Helpers.CommonConstants.MessageType] = "2"; } else { throw new Exception(); } } return RedirectToAction("CreateUser", new { @id = Methods.base64Encode(nUserId.ToString()) }); } catch (Exception ex) { CommonRepository.LogError(sController, "CreateUser", ex.ToString()); Session[Helpers.CommonConstants.Message] = Messages.GetMessage("[Error]"); Session[Helpers.CommonConstants.MessageType] = "2"; return RedirectToAction("viewusers"); } }
/// <summary> /// Action to open user listing page /// </summary> /// <returns></returns> public ActionResult viewusers() { try { User objUserModel = new User(); DataSet ds = objDBGHC_Users.GHC_Users_GetAll("dDateAdded", "DESC"); if (ds != null && ds.Tables[1] != null) { List<GHC_UsersData> sList = new List<GHC_UsersData>(); foreach (DataRow row in ds.Tables[1].Rows) { var nRecord = new GHC_UsersData(); nRecord.nUserID = Methods.doLong(row["nUserID"]); nRecord.sFirstName = Methods.CorrectDBNull(row["sFirstName"]); nRecord.sLastName = Methods.CorrectDBNull(row["sLastName"]); nRecord.sEmail = Methods.CorrectDBNull(row["sEmail"]); nRecord.sPassword = Methods.CorrectDBNull(row["sPassword"]); nRecord.sCity = Methods.CorrectDBNull(row["sCity"]); nRecord.nStateID = Methods.doInt(row["nStateID"]); nRecord.sZipCode = Methods.CorrectDBNull(row["sZipCode"]); nRecord.nCountryID = Methods.doInt(row["nCountryID"]); nRecord.bIsActive = Methods.doBoolean(row["bIsActive"]); nRecord.sUserType = Methods.CorrectDBNull(row["sUserType"]); sList.Add(nRecord); } objUserModel.objGHC_UsersDataList = sList; } return View(objUserModel); } catch (Exception ex) { CommonRepository.LogError(sController, "ViewUsers", ex.ToString()); Session[Helpers.CommonConstants.Message] = Messages.GetMessage("[Error]"); Session[Helpers.CommonConstants.MessageType] = "2"; return RedirectToAction("index", "dashboard"); } }