/// <summary> /// Get Report to display /// </summary> /// <param name="rptType"></param> /// <param name="van"></param> /// <param name="fromDate"></param> /// <param name="toDate"></param> /// <returns></returns> public JsonResult GetReports(string rptType, string van, DateTime fromDate, DateTime toDate) { var model = new List <ReportModel>(); int fromMnth = Convert.ToInt32(fromDate.ToString().Split('/')[0]); int toMnth = Convert.ToInt32(toDate.ToString().Split('/')[0]); DataTable dtReport = AccountDbAccess.GetReport(rptType, van, fromMnth, toMnth); DataTable dtQuestions = AccountDbAccess.GetQuestions(rptType); if (dtReport != null && dtQuestions != null) { DataTable dtResult = SubFunctions.DesignReport(dtReport, dtQuestions, rptType); if (dtResult != null) { foreach (DataRow row in dtResult.Rows) { model.Add(new ReportModel { OrderId = Convert.ToInt32(row["OrderId"]), QuestionId = row["QuestionId"].ToString(), Question = row["Question"].ToString(), T3B = row["T3B"].ToString(), Details = row["Details"].ToString(), Total = row["Total"].ToString() }); } return(Json(new { data = model }, JsonRequestBehavior.AllowGet)); } } return(null); }
public JsonResult EditedEmailExist(string email) { string emailError; if (!AccountDbAccess.IsExistingEmail(email, out emailError)) { return(Json(emailError, JsonRequestBehavior.AllowGet)); } return(Json(" ", JsonRequestBehavior.AllowGet)); }
/// <summary> /// Partial view ChangePassword /// </summary> /// <returns></returns> public ActionResult ChangePassword(string userId = null, string id = null) { var model = new ChangePasswordModel(); AccountDbAccess ADA = new AccountDbAccess(); string userEmail = null; if (userId != null) { userEmail = ADA.GetUserByUserId(userId); //If no user was loaded, output error message if (userEmail == null) { //Show error msg; ViewBag.HideForm = true; return(PartialView(model)); } else { model.email = userEmail; ViewBag.HideForm = false; return(PartialView(model)); } } else if (id != null) { userEmail = ADA.GetUser(id); //isGuidReset = true; //If no user was loaded, output error message if (userEmail == null) { //Show error msg; ViewBag.HideForm = true; return(PartialView(model)); } else { model.email = userEmail; ViewBag.HideForm = false; return(PartialView(model)); } } ViewBag.HideForm = true; return(PartialView(model)); }
/// <summary> /// Load page to Edit user /// </summary> /// <param name="userId"></param> /// <returns></returns> public ActionResult EditUser(int userId) { AccountDbAccess ADA = new AccountDbAccess(); DataTable dtUserDetails = ADA.LoadUserDetails(userId); if (dtUserDetails != null) { var model = new EditUserModel { FirstName = dtUserDetails.Rows[0]["FirstName"].ToString(), LastName = dtUserDetails.Rows[0]["LastName"].ToString(), Email = dtUserDetails.Rows[0]["Email"].ToString(), Phone = dtUserDetails.Rows[0]["Phone"].ToString(), selectedGroupId = dtUserDetails.Rows[0]["GroupID"].ToString(), SeletedStatusId = dtUserDetails.Rows[0]["Active"].ToString(), }; model.UserId = userId; model.groupList = new List <ItemsList>(); model.statusList = new List <ItemsList>() { new ItemsList { Value = "1", Text = "Active" }, new ItemsList { Value = "0", Text = "InActive" } }; DataTable dtGroups = AccountDbAccess.LoadGroupOptions(); foreach (DataRow row in dtGroups.Rows) { model.groupList.Add(new ItemsList { Value = row["GroupID"].ToString(), Text = row["GroupName"].ToString() }); } TempData["groupList"] = model.groupList; TempData["statusList"] = model.statusList; return(PartialView(model)); } else { // show error message here and redirect ToString error page return(null); } }
public ActionResult AddUser(AddUserModel model) { string emailError; model.groupList = (List <ItemsList>)TempData["groupList"]; TempData.Keep(); if (!AccountDbAccess.IsExistingEmail(model.Email, out emailError)) { ModelState.AddModelError("Email", "This email address is already used for another user. Please use a unique email address."); } if (ModelState.IsValid) { int createdUserId = 1; int msg; string temporaryPswd = CommonFunctions.CreatePassword(); if (temporaryPswd != null) { AccountDbAccess.AddNewuser(model.Email, temporaryPswd, model.FirstName, model.LastName, model.Email, model.Phone, Convert.ToInt32(model.selectedGroupId), createdUserId, out msg); if (msg == 0) { //Send mail to created user with username and password if (!SubFunctions.SendNewAccountMail(model.Email, model.FirstName, model.LastName, model.Email, temporaryPswd)) { //Show email error msg here } return(JavaScript("window.top.location.href ='" + Url.Action("Index", "UserManagement", new { area = "User" }) + "';")); } else { return(PartialView(model)); } } else { return(PartialView(model)); } } else { return(PartialView(model)); } }
public JsonResult DeleteUser(int userId) { string delMsg; int msg = AccountDbAccess.DeleteUser(userId); if (msg == 1) { delMsg = UserResource.Success_DeleteUser; } else { delMsg = UserResource.Error_DeleteUser; } return(Json(delMsg, JsonRequestBehavior.AllowGet)); }
public ActionResult EditUser(EditUserModel model) { model.groupList = (List <ItemsList>)TempData["groupList"]; model.statusList = (List <ItemsList>)TempData["statusList"]; int modifiedUserID = 1; if (ModelState.IsValid) { string msgEditUser = AccountDbAccess.UpdateUser(model.UserId, modifiedUserID, model.FirstName, model.LastName, model.Email, model.Phone, Convert.ToInt32(model.selectedGroupId), Convert.ToInt32(model.SeletedStatusId)); return(JavaScript("window.top.location.href ='" + Url.Action("Index", "UserManagement", new { area = "User" }) + "';")); } else { return(PartialView(model)); } }
/// <summary> /// Load page to Add user /// </summary> /// <returns></returns> public ActionResult AddUser() { var model = new AddUserModel(); model.groupList = new List <ItemsList>(); DataTable dtGroups = AccountDbAccess.LoadGroupOptions(); foreach (DataRow row in dtGroups.Rows) { model.groupList.Add(new ItemsList { Value = row["GroupID"].ToString(), Text = row["GroupName"].ToString() }); } model.selectedGroupId = dtGroups.Rows[0]["GroupID"].ToString(); TempData["groupList"] = model.groupList; return(PartialView(model)); }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { int outputMessage; AccountDbAccess ADA = new AccountDbAccess(); ADA.LogInUser(model.userName, model.password, true, Config.clientId, out outputMessage); LoginErrorCode errorCode = (LoginErrorCode)outputMessage; if (outputMessage == 0) { //Check is this first login, then redirect to change password if (UserInfoModel.PasswordExpireDate < DateTime.Now) { return(RedirectToAction("ChangePassword", new { @userId = UserInfoModel.UserID })); } ViewBag.message = "Successfully loggedIn"; ViewBag.messageType = "success"; return(JavaScript("window.top.location.href ='" + Url.Action("Index", "Home", new { area = "" }) + "';")); } else { ModelState.AddModelError("LoginModel", "Login failed"); ViewBag.message = "Login failed"; ViewBag.messageType = "error"; } } else { ModelState.AddModelError("Login", "Login failed"); ViewBag.message = "Login failed"; ViewBag.messageType = "error"; } return(PartialView(model)); }
/// <summary> /// Get users list /// </summary> /// <returns></returns> public JsonResult GetUsersList() { var model = new List <UserModel>(); AccountDbAccess ADA = new AccountDbAccess(); DataTable dt = ADA.GetUsersList(1); foreach (DataRow row in dt.Rows) { //DateTime? LtLogin = Convert.ToDateTime(row["LastLogin"]); model.Add(new UserModel { UserId = Convert.ToInt32(row["UserID"]), FullName = row["FullName"].ToString(), Email = row["Email"].ToString(), Group = row["Group"].ToString(), Status = Convert.ToBoolean(row["Status"]), LastLogin = row["LastLogin"].ToString() //LastLogin = row["LastLogin"] != DBNull.Value ? Convert.ToDateTime(row["LastLogin"]) : (DateTime?)null }); } return(Json(new { data = model }, JsonRequestBehavior.AllowGet)); }
public AccountService(AccountDbAccess dataAccess) { _dataAccess = dataAccess; }
public ActionResult ChangePassword(ChangePasswordModel model) { if (ModelState.IsValid) { //Validate new password if (model.newPswd != model.confirmPswd) { ViewBag.message = AccountResource.ResourceManager.GetString("passwordMismatch"); ViewBag.messageType = MessageTypes.Error; return(PartialView(model)); } if (UserInfoModel.UserID <= 0) { ViewBag.message = AccountResource.ResourceManager.GetString("error_PswdChange"); ViewBag.messageType = MessageTypes.Error; return(PartialView(model)); } else { AccountDbAccess ADA = new AccountDbAccess(); string resetError; if (!ADA.UpdatePassword(UserInfoModel.UserID, model.newPswd, out resetError)) { ViewBag.message = resetError; ViewBag.messageType = MessageTypes.Error; return(PartialView(model)); } //Clears login attempt History for specified userId int rows = ADA.ClearLoginAttempts(UserInfoModel.UserID); //Get user with new password to make sure that everything is OK int outputValue; ADA.LogInUser(model.email, model.newPswd, true, Config.clientId, out outputValue); if (outputValue == 0) { ViewBag.message = "Successfully changed password"; ViewBag.messageType = "success"; return(JavaScript("window.top.location.href ='" + Url.Action("Index", "Login", new { area = "Account" }) + "';")); } else { //UserInfoModel.UserInfo = SessionWrapper.Get<UserInfoModel>("UserDetail", null); ViewBag.message = AccountResource.ResourceManager.GetString("criticalError"); ViewBag.messageType = MessageTypes.Error; return(PartialView(model)); } } } else { ModelState.AddModelError("Login", "Password couldn't change"); ViewBag.message = "Password change failed"; ViewBag.messageType = "error"; } return(PartialView(model)); }
/// <summary> /// Load chart data /// </summary> /// <returns></returns> public JsonResult GetChartData(string reportType) { int fromMnth = Convert.ToInt32(TempData["frDt"].ToString().Split('/')[0]); int toMnth = 12; //int toMnth = Convert.ToInt32(TempData["toDt"].ToString().Split('/')[0]); //Load Report details DataTable dtReport = AccountDbAccess.GetMonthlyRecordOfQuestion(reportType, TempData["qnId"].ToString(), fromMnth, toMnth); if (dtReport != null) { var model = new ReportChartModel(); model.ChartDataList = new List <ReportChartData>(); model.QusetionId = TempData["qnId"].ToString(); switch (dtReport.Columns.Count) { case 4: model.FieldType = ChartTypes.OneField.ToString(); break; case 5: model.FieldType = ChartTypes.TwoField.ToString(); break; case 6: model.FieldType = ChartTypes.ThreeField.ToString(); break; case 8: model.FieldType = ChartTypes.FiveField.ToString(); break; } foreach (DataRow row in dtReport.Rows) { if (model.FieldType == ChartTypes.OneField.ToString()) { model.ChartDataList.Add(new ReportChartData { Data1 = row["Ans"].ToString(), Total = row["Total"].ToString(), ReportMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Convert.ToInt32(row["ReportMonth"])), }); } else if (model.FieldType == ChartTypes.TwoField.ToString()) { model.ChartDataList.Add(new ReportChartData { Data1 = row["YES"].ToString(), Data2 = row["NO"].ToString(), Total = row["Total"].ToString(), ReportMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Convert.ToInt32(row["ReportMonth"])), }); } else if (model.FieldType == ChartTypes.ThreeField.ToString()) { model.ChartDataList.Add(new ReportChartData { Data1 = row["YES"].ToString(), Data2 = row["NO"].ToString(), Data3 = row["NA"].ToString(), Total = row["Total"].ToString(), ReportMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Convert.ToInt32(row["ReportMonth"])), }); } else if (model.FieldType == ChartTypes.FiveField.ToString()) { model.ChartDataList.Add(new ReportChartData { Data1 = row["VD"].ToString(), Data2 = row["SD"].ToString(), Data3 = row["SS"].ToString(), Data4 = row["VS"].ToString(), Data5 = row["NA"].ToString(), Total = row["Total"].ToString(), ReportMonth = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Convert.ToInt32(row["ReportMonth"])), }); } } return(Json(new { data = model }, JsonRequestBehavior.AllowGet)); } else { return(null); } }