public void LogOut(int pageId = 0) { if (null != UserSession) { using (ITransaction tx = PersistenceSession.BeginTransaction()) { try { UserSession.SessionPeriod.To = DateTime.Now; UserSession.LogoutMessage = "Logout"; UserSession.Save(this); Log(0, pageId, 0, MessageException.AuthenMessage.Logout, MessageException.Success(User.ID.ToString())); tx.Commit(); } catch (Exception ex) { Log(0, pageId, 0, MessageException.AuthenMessage.Logout, MessageException.Fail(ex.Message)); throw; } } } }
public JsonResult SaveComment(long projectId, string comment) { try { Project p = Project.GetProjectByID(SessionContext, projectId); if (p == null) { SessionContext.Log(0, this.pageID, 0, MessageException.ProjectMessage.Get, MessageException.Null("The static method Get return null, ID : " + projectId)); return(Json(new { Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { p.CommentAction = new UserAction(SessionContext.User); p.CommentAction.Remark = comment; p.StatusCategory = StatusCategory.Commented; p.Status = Status.Comment; SessionContext.Persist(p); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.ProjectMessage.SaveComment, MessageException.Success()); } catch (Exception ex) { tx.Rollback(); SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.ProjectMessage.SaveComment, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { SessionContext.LogButNotFlush(0, pageID, 0, MessageException.ProjectMessage.Comment, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, Message = "บันทึกเรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateResponsibleOrgUnits(long[] agencies) { try { if (agencies.Length <= 0) { return(Json(new { Success = true, Message = "กรุณาตรวจสอบข้อมูล" }, JsonRequestBehavior.AllowGet)); } SelfAuthenticatedUser user = SessionContext.User; //Expire all foreach (var item in user.ResponsibleOrgUnits) { item.EffectivePeriod = new TimeInterval(TimeInterval.MaxDate, TimeInterval.MinDate); } //update for (int i = 0; i < agencies.Length; i++) { if (user.ResponsibleOrgUnits.Any(x => x.OrgUnit.ID == agencies[i])) { user.ResponsibleOrgUnits.Where(x => x.OrgUnit.ID == agencies[i]).SingleOrDefault().EffectivePeriod = TimeInterval.EffectiveNow; } else { UserOrgUnit userOrgUnitNew = new UserOrgUnit(user, OrgUnit.Find(SessionContext, agencies[i])); user.ResponsibleOrgUnits.Add(userOrgUnitNew); } } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { SessionContext.Persist(user); tx.Commit(); SessionContext.Log(0, pageID, 0, MessageException.ProjectMessage.EditProfile, MessageException.Success(user.LoginName)); } catch (Exception ex) { tx.Rollback(); SessionContext.LogButNotFlush(0, pageID, 0, MessageException.ProjectMessage.EditProfile, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Success = true, Message = "บันทึกเรียบร้อย" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { SessionContext.LogButNotFlush(0, pageID, 0, MessageException.ProjectMessage.EditProfile, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } }
public JsonResult UpdateBasicInfo(long pId, string original, string urgency) { Project project = null; if (string.IsNullOrEmpty(original) || string.IsNullOrEmpty(urgency)) { SessionContext.Log(0, this.PageID, 0, MessageException.ProjectMessage.UpdateBasicInfo, MessageException.Null("The original or urgency emptry.")); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { project = SessionContext.PersistenceSession.Get <Project>(pId); project.OriginOfProject = original; project.UrgencyOfProject = urgency; project.CreateAction = new iSabaya.UserAction(SessionContext.User); project.StatusCategory = StatusCategory.Update; project.Status = Status.SaveBasicInfo; SessionContext.Persist(project); tx.Commit(); SessionContext.Log(0, this.PageID, 0, MessageException.ProjectMessage.UpdateBasicInfo, MessageException.Success()); } catch (Exception ex) { tx.Rollback(); SessionContext.LogButNotFlush(0, this.PageID, 0, MessageException.ProjectMessage.UpdateBasicInfo, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Success = true, Message = "บันทึก ข้อมูลพื้นฐานโครงการ เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult Delete(long id) { Announce announce = Announce.Get(SessionContext, id); if (announce == null) { SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Delete, MessageException.Null("The static method Get return null, ID : " + id)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { announce.Delete(SessionContext); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Delete, MessageException.Success(id.ToString())); } catch (Exception ex) { tx.Rollback(); SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Delete, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Success = true, Message = "ลบประกาศ เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult DeleteUsers(string id) { StringBuilder message = new StringBuilder(); message.Append("<b>ลบ บัตรประชาชน</b> <br/>"); int successCount = 0; //int failCount = 0; string[] param = id.Split(','); try { if (string.IsNullOrEmpty(id)) { SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Delete, MessageException.Fail("The ID is Emrpty")); return(Json(new { Success = false, Message = MessageException.PleaseSelectUser }, JsonRequestBehavior.AllowGet)); } message.Append("<ul>"); //Add logic here for (int i = 0; i < param.Length; i++) { iSabaya.SelfAuthenticatedUser u = SessionContext.PersistenceSession.Get <iSabaya.SelfAuthenticatedUser>(Int64.Parse(param[i])); if (u != null) { using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { u.EffectivePeriod = new iSabaya.TimeInterval { ExpiryDate = DateTime.Now }; u.UpdateAction = new iSabaya.UserAction(SessionContext.User); u.Persist(SessionContext); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Delete, MessageException.Success(id)); successCount++; message.Append(string.Format("<li>{0}</li>", u.Person.OfficialIDNo)); } catch (Exception ex) { tx.Rollback(); SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Delete, MessageException.Fail(ex.Message)); } } } } message.Append("</ul>"); } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Delete, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } message.Append(string.Format("ลบผู้ที่ถูกเลือกสำเร็จ {0} / {1} แถว", successCount, param.Length)); return(Json(new { Success = true, Message = message.ToString() }, JsonRequestBehavior.AllowGet)); }
public JsonResult Save(string name) { try { if (string.IsNullOrEmpty(name)) { SessionContext.Log(0, this.pageID, 0, MessageException.StrategicMessage.Save, MessageException.Fail("The name is emptry.")); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { Strategic strategic = new Strategic { Name = name, }; strategic.CreateAction = new UserAction(SessionContext.User); strategic.EffectivePeriod = TimeInterval.EffectiveNow; SessionContext.Persist(strategic); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.StrategicMessage.Save, MessageException.Success()); } catch (Exception ex) { tx.Rollback(); SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.StrategicMessage.Save, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.StrategicMessage.Save, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, Message = "เพิ่มนโยบายเชิงยุทธศาสตร์ เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult Update(long id, string name) { try { if (string.IsNullOrEmpty(name)) { SessionContext.Log(0, this.pageID, 0, MessageException.StrategicMessage.Update, MessageException.Fail("The name is emptry.")); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } Strategic strategic = Strategic.Get(SessionContext, id); if (strategic == null) { return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { strategic.Name = name; //strategic.EffectivePeriod.From = DateTime.Now; strategic.UpdateAction = new UserAction(SessionContext.User); strategic.EffectivePeriod = TimeInterval.EffectiveNow; strategic.Persist(SessionContext); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.StrategicMessage.Update, MessageException.Success(id.ToString())); } catch (Exception ex) { tx.Rollback(); SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.StrategicMessage.Update, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.StrategicMessage.Update, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, Message = "แก้ไขนโยบายเชิงยุทธศาสตร์ เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult Save(string name) { try { if (string.IsNullOrEmpty(name)) { SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Save, MessageException.Null("The name is emptry.")); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { GoodGovernance goodGovernance = new GoodGovernance { Name = name }; goodGovernance.Persist(SessionContext); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Save, MessageException.Success()); } catch (Exception ex) { tx.Rollback(); SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Save, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Save, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, Message = "เพิ่มหลักธรรมาภิบาล เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult Update(long id, string name) { try { if (string.IsNullOrEmpty(name)) { SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Update, MessageException.Null("The name is emptry.")); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } GoodGovernance goodGovernance = GoodGovernance.Get(SessionContext, id); if (goodGovernance == null) { SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Update, MessageException.Null("The static method Get return null, ID : " + id)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { goodGovernance.Name = name; goodGovernance.EffectivePeriod.From = DateTime.Now; tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Update, MessageException.Success(id.ToString())); } catch (Exception ex) { tx.Rollback(); SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Update, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.GoodGovernanceMessage.Update, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, Message = "แก้ไขหลักธรรมาภิบาล เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public string Authentication(string idCard, string nameEng, string status) { try { WebLogger.Warn("Authenticating"); Dictionary <string, object> jsonResult = new Dictionary <string, object>(); User user = null; switch (AuthenticateManager.Authenticate(SessionContext, SystemEnum.RiskAssessmentAnalysisSystem, idCard, nameEng, ref user)) { case AuthenticateManager.AuthenState.AuthenticationSuccess: BudgetConfiguration.CurrentConfiguration = GetConfiguration(SessionContext, SessionContext.MySystem.SystemID); SessionContext.StartNewSession(user, Session.SessionID); string targetPath = ""; switch (user.UserRoles[0].Role.Id) { case 1: targetPath = FullUrl("Government"); //ส่วนราชการ break; case 2: targetPath = FullUrl("Budgetor"); //ทำงบประมาณ break; case 3: targetPath = FullUrl("Evaluation"); //เจ้าหน้าที่ประเมินงบ break; case 4: targetPath = FullUrl("Admin"); //ผู้ดูแลระบบ break; default: throw new Exception("User Role Invalid."); } jsonResult.Add("result", 1); jsonResult.Add("target", targetPath); jsonResult.Add("message", ""); SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Success(SessionContext.User.ID.ToString())); break; case AuthenticateManager.AuthenState.AuthenticationFail: jsonResult.Add("result", 0); jsonResult.Add("target", ""); jsonResult.Add("message", "Login Failed."); SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(string.Format("{0} : {1}", idCard, nameEng))); break; case AuthenticateManager.AuthenState.AlreadyLogin: jsonResult.Add("result", 0); jsonResult.Add("target", ""); jsonResult.Add("message", "Login Failed."); SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(user.ID.ToString() + " : Login Attemp.")); break; default: break; } WebLogger.Warn("End Authenticating"); return(new JavaScriptSerializer().Serialize(jsonResult)); #region old //Dictionary<string, object> jsonResult = new Dictionary<string, object>(); //IList<SelfAuthenticatedUser> users = SessionContext.PersistenceSession.QueryOver<SelfAuthenticatedUser>().List(); //IList<SelfAuthenticatedUser> user = users.Where(s => s.LoginName.ToLowerInvariant() == nameEng.ToLowerInvariant() // && s.Person.OfficialIDNo == idCard // && s.UserRoles[0].Role.Id == int.Parse(status) // && !s.IsDisable // && s.IsEffective).ToList(); //if (0 < user.Count) //{ // if (user.Count != 1) { throw new Exception("User have more than one. System error."); } // //if (!user[0].IsBuiltin) // //{ // // IList<iSabaya.UserSession> userSessions = SessionContext.PersistenceSession // // .QueryOver<iSabaya.UserSession>() // // .Where(us => us.User.ID == user[0].ID // // && us.SessionPeriod.To == iSabaya.TimeInterval.MaxDate) // // .List(); // // if (userSessions.Any(u => u.User.ID == user[0].ID)) // // { // // jsonResult.Add("result", 0); // // jsonResult.Add("target", ""); // // jsonResult.Add("message", "Login Failed."); // // SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(userSessions[0].User.ID.ToString() + " : Login Attemp.")); // // //SessionContext.StartFailedSession(null, idCard, Session.SessionID, "Login Attemp."); // // return new JavaScriptSerializer().Serialize(jsonResult); // // } // //} // BudgetConfiguration.CurrentConfiguration = GetConfiguration(SessionContext, SessionContext.MySystem.SystemID); // SessionContext.StartNewSession(user[0], Session.SessionID); // string targetPath = ""; // switch (user[0].UserRoles[0].Role.Id) // { // //case 1: // // targetPath = FullUrl("Government");//ส่วนราชการ // // break; // case 2: // targetPath = FullUrl("Budgetor");//ทำงบประมาณ // break; // case 3: // targetPath = FullUrl("Evaluation");//เจ้าหน้าที่ประเมินงบ // break; // //case 4: // // targetPath = FullUrl("Admin");//ผู้ดูแลระบบ // // break; // default: // throw new Exception("User Role Invalid."); // } // jsonResult.Add("result", 1); // jsonResult.Add("target", targetPath); // jsonResult.Add("message", ""); // SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Success(SessionContext.User.ID.ToString())); //} //else //{ // jsonResult.Add("result", 0); // jsonResult.Add("target", ""); // jsonResult.Add("message", "Login Failed."); // SessionContext.Log(0, pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail()); // //SessionContext.StartFailedSession(null, idCard, Session.SessionID, "Login Failed."); //} //WebLogger.Warn("End Authenticating"); //return new JavaScriptSerializer().Serialize(jsonResult); #endregion old } catch (Exception ex) { WebLogger.Error(ex.GetAllMessages()); Dictionary <string, object> jsonResult = new Dictionary <string, object>(); jsonResult.Add("result", 0); jsonResult.Add("target", ""); jsonResult.Add("message", ex.ToString()); //SessionContext.StartFailedSession(null, idCard, Session.SessionID, ex.Message); SessionContext.Log(0, this.pageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(ex.Message)); return(new JavaScriptSerializer().Serialize(jsonResult)); } }
public JsonResult EnableUsers(string id) { StringBuilder message = new StringBuilder(); message.Append("<b>เปิดใช้งาน บัตรประชาชน</b> <br/>"); int successCount = 0; int failCount = 0; string[] param = id.Split(','); try { if (string.IsNullOrEmpty(id)) { SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Enable, MessageException.Fail("The ID is Emrpty")); return(Json(new { Success = false, Message = MessageException.PleaseSelectUser }, JsonRequestBehavior.AllowGet)); } message.Append("<ul>"); //Add logic here for (int i = 0; i < param.Length; i++) { iSabaya.SelfAuthenticatedUser u = SessionContext.PersistenceSession.Get <iSabaya.SelfAuthenticatedUser>(Int64.Parse(param[i])); if (u.ID == SessionContext.User.ID) { message.Append(string.Format("<li>ไม่สามารถเปิดใช้งาน {0} ได้</li>", u.Person.OfficialIDNo)); } else { if (u != null) { using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { if (u.IsDisable) { u.IsDisable = false; } // is first regist only if (u.IsNotFinalized) { u.IsNotFinalized = false; u.ApproveAction = new iSabaya.UserAction(SessionContext.User); } u.UpdateAction = new iSabaya.UserAction(SessionContext.User); u.Persist(SessionContext); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Enable, MessageException.Success(u.ID.ToString())); successCount++; message.Append(string.Format("<li>{0}</li>", u.Person.OfficialIDNo)); } catch (Exception ex) { tx.Rollback(); SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.UserMessage.Enable, MessageException.Fail(ex.Message)); failCount++; } } } } } message.Append("</ul>"); } catch (Exception ex) { SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.UserMessage.Enable, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } message.Append(string.Format("เปิดใช้งานผู้ที่ถูกเลือกสำเร็จ {0} / {1} แถว", successCount, param.Length)); return(Json(new { Success = true, Message = message.ToString() }, JsonRequestBehavior.AllowGet)); }
public JsonResult Save(string code, string name) { try { IList <Organization> organizations = Organization.List(SessionContext); if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(name)) { SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Save, MessageException.Null("The code or name is emptry.")); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } if (organizations.Any(x => x.Code == code) || organizations.Any(x => x.CurrentName.Name.GetValue("th-TH") == name)) { SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Save, MessageException.Fail("The ministry is existing in database.")); return(Json(new { Success = false, Message = "ไม่สามารถเพิ่มกระทรวงได้ เนื่องจากมีอยู่ในระบบแล้ว" }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { Organization org = new Organization { Code = code.Trim(), CurrentName = new OrgName { Name = new MultilingualString("th-TH", name.Trim(), "en-US", name.Trim()), } }; org.Persist(SessionContext); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Save, MessageException.Success()); } catch (Exception ex) { tx.Rollback(); SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Save, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Save, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, Message = "เพิ่มกระทรวง เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public string Authentication(string idCard, string nameEng, string status) { try { SessionContext.PersistenceSession.Clear(); WebLogger.Warn("Authenticating"); var jsonResult = new Dictionary <string, object>(); User user = null; BudgetConfiguration.CurrentConfiguration = GetConfiguration(SessionContext, SessionContext.MySystem.SystemID); switch (AuthenticateManager .Authenticate(SessionContext, SystemEnum.RiskAssessmentProjectOwnerSystem, idCard, nameEng, ref user)) { case AuthenticateManager.AuthenState.AuthenticationSuccess: SessionContext.StartNewSession(user, Session.SessionID); var targetPath = ""; switch (user.UserRoles[0].Role.Id) { case 1: targetPath = FullUrl("Government"); //ส่วนราชการ break; case 2: targetPath = FullUrl("Budgetor"); //ทำงบประมาณ break; case 3: targetPath = FullUrl("Evaluation"); //เจ้าหน้าที่ประเมินงบ break; case 4: targetPath = FullUrl("Admin"); //ผู้ดูแลระบบ break; default: throw new Exception("User Role Invalid."); } jsonResult.Add("result", 1); jsonResult.Add("target", targetPath); jsonResult.Add("message", ""); SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Login, MessageException.Success(SessionContext.User.ID.ToString())); break; case AuthenticateManager.AuthenState.AuthenticationFail: jsonResult.Add("result", 0); jsonResult.Add("target", ""); jsonResult.Add("message", "Login Failed."); SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(string.Format("{0} : {1}", idCard, nameEng))); break; case AuthenticateManager.AuthenState.AlreadyLogin: jsonResult.Add("result", 0); jsonResult.Add("target", ""); jsonResult.Add("message", "Login Failed."); SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Login, MessageException.Fail(user.ID.ToString() + " : Login Attemp.")); break; default: break; } WebLogger.Warn("End Authenticating"); return(new JavaScriptSerializer().Serialize(jsonResult)); } catch (Exception ex) { WebLogger.Error(ex.GetAllMessages()); var jsonResult = new Dictionary <string, object>(); jsonResult.Add("result", 0); jsonResult.Add("target", ""); jsonResult.Add("message", ex.ToString()); SessionContext.StartFailedSession(null, idCard, Session.SessionID, ex.Message); SessionContext.Log(0, this.PageID, 0, "Login", "Fail : " + ex.Message); return(new JavaScriptSerializer().Serialize(jsonResult)); } }
public JsonResult SaveAnswerB6(long pId, bool choice, string answer1, string answer2) { Project project = null; if (choice) { if (string.IsNullOrEmpty(answer1) || string.IsNullOrEmpty(answer2)) { SessionContext.Log(0, this.PageID, 0, MessageException.ProjectMessage.UpdateAnswerB6, MessageException.Null("The answer of Question B6 is emptry.")); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { project = SessionContext.PersistenceSession.Get <Project>(pId); project.CreateAction = new iSabaya.UserAction(SessionContext.User); project.StatusCategory = StatusCategory.Update; project.Status = Status.SaveAnswerSetB6; SessionContext.Persist(project); tx.Commit(); SessionContext.Log(0, this.PageID, 0, MessageException.ProjectMessage.UpdateAnswerB6, MessageException.Success()); } catch (Exception ex) { tx.Rollback(); SessionContext.LogButNotFlush(0, this.PageID, 0, MessageException.ProjectMessage.UpdateAnswerB6, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Success = true, Message = "บันทึก คำถามที่ 6 เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult RegisterStaff(string idCard, string firstNameTH, string lastNameTH, string firstNameEN, string lastNameEN, string address, string telephone, string toNumber, string directTelephone , string mobilePhone, string email, string institute, int roleId, long ministryId, long[] agencies) { try { if (string.IsNullOrEmpty(idCard) || string.IsNullOrEmpty(firstNameTH) || string.IsNullOrEmpty(lastNameTH) || string.IsNullOrEmpty(firstNameEN) || string.IsNullOrEmpty(lastNameEN) || string.IsNullOrEmpty(address) || string.IsNullOrEmpty(email) || roleId < 0 || ministryId < 0 || agencies.Length <= 0) { return(Json(new { Success = true, Message = "กรุณาตรวจสอบข้อมูล" }, JsonRequestBehavior.AllowGet)); } if (SessionContext.PersistenceSession.QueryOver <iSabaya.User>().List().Any(x => x.Person.OfficialIDNo == idCard)) { return(Json(new { Success = false, Message = "เลขบัตรประชาชนนี้ได้ลงทะเบียนแล้ว ไม่สามารถลงทะเบียนซ้ำได้" }, JsonRequestBehavior.AllowGet)); } Organization org = SessionContext.PersistenceSession.QueryOver <Organization>().Where(o => o.Code == "01000").SingleOrDefault(); //กระทรวงสำนักนายกรัฐมนตรี 01000 OrgUnit orgUnit = SessionContext.PersistenceSession.QueryOver <OrgUnit>().Where(o => o.Code == "01007").SingleOrDefault(); //หน่วยงาน สำนักงบประมาณ 01007 SelfAuthenticatedUser user = new SelfAuthenticatedUser( SessionContext.MySystem.SystemID, org, orgUnit, idCard, firstNameEN, firstNameTH, firstNameEN, lastNameTH, lastNameEN, "", "", email, mobilePhone, telephone, toNumber, directTelephone, address); // user is first register , user is not active and then administrator activate user.IsDisable = true; // set is not finali flag to admin activate and update approve action user.IsNotFinalized = true; user.UserRoles = new List <UserRole> { new UserRole(user, SessionContext.PersistenceSession .QueryOver <iSabaya.Role>().List() .SingleOrDefault(x => x.Id == roleId)) }; IList <UserOrgUnit> userOrgUnits = new List <UserOrgUnit>(); for (int i = 0; i < agencies.Length; i++) { userOrgUnits.Add(new UserOrgUnit(user, OrgUnit.Find(SessionContext, agencies[i]))); } user.ResponsibleOrgUnits = userOrgUnits; using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { user.Persist(SessionContext); tx.Commit(); SessionContext.Log(0, pageID, 0, MessageException.RegisterMessage.StaffRegister, MessageException.Success(user.LoginName)); } catch (Exception ex) { tx.Rollback(); SessionContext.Log(0, pageID, 0, MessageException.RegisterMessage.StaffRegister, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Success = true, Message = "บันทึกเรียบร้อย" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { SessionContext.Log(0, pageID, 0, MessageException.RegisterMessage.StaffRegister, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } }
public JsonResult Update(long id, string code, string name) { try { if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(name)) { SessionContext.Log(0, this.pageID, 0, MessageException.DepartmentMessage.Update, MessageException.Null("The code or name is emptry.")); return(Json(new { Success = false, Message = MessageException.PleaseFillOut }, JsonRequestBehavior.AllowGet)); } OrgUnit orgUnit = OrgUnit.Find(SessionContext, id); if (orgUnit == null) { SessionContext.Log(0, this.pageID, 0, MessageException.DepartmentMessage.Update, MessageException.Fail("The static method Find return null, ID : " + id)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { orgUnit.Code = code.Trim(); orgUnit.CurrentName.Name = new MultilingualString("th-TH", name.Trim(), "en-US", name.Trim()); orgUnit.Persist(SessionContext); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.DepartmentMessage.Update, MessageException.Success()); } catch (Exception ex) { tx.Rollback(); SessionContext.Log(0, this.pageID, 0, MessageException.DepartmentMessage.Update, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.DepartmentMessage.Update, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, Message = "แก้ไขข้อมูลหน่วยงาน เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult Save(string code, string name) { try { IList <Organization> organizations = Organization.List(SessionContext); if (IsMinistryValid(code, name)) { SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Save, MessageException.Null("The code or name is emptry.")); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } if (IsMinitryCodeAlreadyExist(code, organizations) || IsMinitryNameAlreadyExist(name, organizations)) { SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Save, MessageException.Fail("The ministry is existing in database.")); return(Json(new { Success = false, Message = "ไม่สามารถเพิ่มกระทรวงได้ เนื่องจากมีอยู่ในระบบแล้ว" }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { var org = new Organization { Code = code.Trim(), CurrentName = new OrgName { Name = new MultilingualString(Formetter.LanguageTh, name.Trim(), Formetter.LanguageEn, name.Trim()), } }; org.Persist(SessionContext); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Save, MessageException.Success()); } catch (Exception ex) { tx.Rollback(); SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.MinistryMessage.Save, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.MinistryMessage.Save, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, Message = "เพิ่มกระทรวง เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult Delete(long id) { try { Strategic strategic = Strategic.Get(SessionContext, id); if (strategic == null) { SessionContext.Log(0, this.pageID, 0, MessageException.StrategicMessage.Delete, MessageException.Null("The static method Get return null, ID : " + id)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { strategic.EffectivePeriod = new TimeInterval(TimeInterval.MaxDate, TimeInterval.MinDate); strategic.UpdateAction = new UserAction(SessionContext.User); //strategic.Delete(SessionContext); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.StrategicMessage.Delete, MessageException.Success(id.ToString())); } catch (Exception ex) { tx.Rollback(); SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.StrategicMessage.Delete, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.StrategicMessage.Delete, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, Message = "ลบนโยบายเชิงยุทธศาสตร์ เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult Update(long id, string code, string name) { try { if (IsDepartmentValid(code, name)) { SessionContext.Log(0, this.pageID, 0, MessageException.DepartmentMessage.Update, MessageException.Null("The code or name is emptry.")); return(Json(new { Success = false, Message = MessageException.PleaseFillOut }, JsonRequestBehavior.AllowGet)); } OrgUnit orgUnit = OrgUnit.Find(SessionContext, id); if (orgUnit == null) { SessionContext.Log(0, this.pageID, 0, MessageException.DepartmentMessage.Update, MessageException.Fail("The static method Find return null, ID : " + id)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } if ((IsDepartmentCodeChanged(code, orgUnit) && IsDepartmentCodeAlreadyExist(code, orgUnit.OrganizationParent.OrgUnits)) || (IsDepartmentNameChanged(name, orgUnit) && IsDepartmentNameAlreadyExist(code, orgUnit.OrganizationParent.OrgUnits))) { SessionContext.Log(0, this.pageID, 0, MessageException.DepartmentMessage.Save, MessageException.Fail("The Departmeny Is Already Exist.")); return(Json(new { Success = false, Message = "ไม่สามารถเพิ่มหน่วยงานได้ เนื่องจากมีอยู่ในระบบแล้ว" }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { orgUnit.Code = code.Trim(); orgUnit.CurrentName.Name = new MultilingualString(Formetter.LanguageTh, name.Trim(), Formetter.LanguageEn, name.Trim()); orgUnit.Persist(SessionContext); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.DepartmentMessage.Update, MessageException.Success()); } catch (Exception ex) { tx.Rollback(); SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.DepartmentMessage.Update, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.DepartmentMessage.Update, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, Message = "แก้ไขข้อมูลหน่วยงาน เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult UnlogUsers(string id) { StringBuilder message = new StringBuilder(); message.Append("<b>ปลดล๊อก บัตรประชาชน</b> <br/>"); int successCount = 0; //int failCount = 0; string[] param = id.Split(','); try { if (string.IsNullOrEmpty(id)) { SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Unlog, MessageException.Fail("The ID is Emrpty")); return(Json(new { Success = false, Message = MessageException.PleaseSelectUser }, JsonRequestBehavior.AllowGet)); } message.Append("<ul>"); //Add logic here for (int i = 0; i < param.Length; i++) { IList <iSabaya.UserSession> userSessions = SessionContext.PersistenceSession .QueryOver <iSabaya.UserSession>() .Where(us => us.User.ID == long.Parse(param[i]) && us.SessionPeriod.To == iSabaya.TimeInterval.MaxDate) .List(); if (userSessions.Count > 0) { successCount++; message.Append(string.Format("<li>{0}</li>", userSessions[0].User.Person.OfficialIDNo)); } foreach (iSabaya.UserSession us in userSessions) { using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { us.SessionPeriod.To = DateTime.Now; us.Save(SessionContext); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Unlog, MessageException.Success(us.ID.ToString())); } catch (Exception ex) { tx.Rollback(); SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Unlog, MessageException.Fail(ex.Message)); } } } } message.Append("</ul>"); } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Unlog, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } message.Append(string.Format("ปลดล๊อกผู้ที่ถูกเลือกสำเร็จ {0} / {1} แถว", successCount, param.Length)); return(Json(new { Success = true, Message = message.ToString() }, JsonRequestBehavior.AllowGet)); }
public ActionResult Logout() { if (SessionContext != null && SessionContext.User != null) { using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { SessionContext.UserSession.SessionPeriod.To = DateTime.Now; SessionContext.UserSession.LogoutMessage = MessageException.AuthenMessage.Logout; SessionContext.UserSession.Save(SessionContext); SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Logout, MessageException.Success(SessionContext.User.ID.ToString())); tx.Commit(); } catch (Exception ex) { WebLogger.Error(ex.Message); SessionContext.Log(0, PageID, 0, MessageException.AuthenMessage.Logout, MessageException.Fail(ex.Message)); tx.Rollback(); } } } Session.Clear(); Session.Abandon(); return(RedirectToAction("Index", "Login")); }
public JsonResult Update(long id, string headLine, string content) { Announce announce = Announce.Get(SessionContext, id); if (announce == null) { SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Update, MessageException.Null("The static method Get return null, ID : " + id)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { announce.HeadLine = headLine; announce.Content = content; announce.UpdateAction = new iSabaya.UserAction(SessionContext.User); announce.EffectivePeriod = iSabaya.TimeInterval.EffectiveNow; announce.Persist(SessionContext); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Update, MessageException.Success(id.ToString())); } catch (Exception ex) { tx.Rollback(); SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Update, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Success = true, Message = "แก้ไขประกาศ เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult SaveBudgetApproved(long projectId, string budgetResult, string budgetAmount = "0") { try { Project p = Project.GetProjectByID(SessionContext, projectId); if (p == null) { SessionContext.Log(0, this.pageID, 0, MessageException.ProjectMessage.Get, MessageException.Null("The static method Get return null, ID : " + projectId)); return(Json(new { Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { p.ApproveAction = new UserAction(SessionContext.User); switch (int.Parse(budgetResult)) { case 0: p.BudgetResult = BudgetResult.Approval; p.BudgetApprovalAmount = decimal.Parse(budgetAmount); break; case 1: p.BudgetResult = BudgetResult.Disapproval; break; case 2: p.BudgetResult = BudgetResult.DisapprovalByBudgetor; break; } p.Status = Status.Approve; p.StatusCategory = StatusCategory.Approved; SessionContext.Persist(p); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.ProjectMessage.SaveComment, MessageException.Success()); } catch (Exception ex) { tx.Rollback(); SessionContext.LogButNotFlush(0, this.pageID, 0, MessageException.ProjectMessage.SaveComment, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } } catch (Exception ex) { SessionContext.LogButNotFlush(0, pageID, 0, MessageException.ProjectMessage.Comment, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, Message = "บันทึกเรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult Save(string headLine, string content) { if (string.IsNullOrEmpty(headLine) || string.IsNullOrEmpty(content)) { SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Save, MessageException.Null("The headLine or content is emptry.")); return(Json(new { Success = false, Message = MessageException.PleaseFillOut }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { Announce announce = new Announce { HeadLine = headLine, Content = content }; announce.CreateAction = new iSabaya.UserAction(SessionContext.User); announce.EffectivePeriod = iSabaya.TimeInterval.EffectiveNow; SessionContext.Persist(announce); tx.Commit(); SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Save, MessageException.Success()); } catch (Exception ex) { tx.Rollback(); SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Save, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Success = true, Message = "เพิ่มประกาศ เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateDetail(long pId, string projectName, int strategicId, string year, string budget, string expenditure) { Project project = null; string projectIdEncryp = string.Empty; if (string.IsNullOrEmpty(projectName) || strategicId <= 0 || string.IsNullOrEmpty(year) || string.IsNullOrEmpty(budget) || string.IsNullOrEmpty(expenditure)) { SessionContext.Log(0, this.PageID, 0, MessageException.ProjectMessage.UpdateDetail, MessageException.Null("There are input project detail emptry.")); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } using (ITransaction tx = SessionContext.PersistenceSession.BeginTransaction()) { try { project = SessionContext.PersistenceSession.Get <Project>(pId); project.Name = projectName; project.Strategic = Strategic.Get(SessionContext, strategicId); project.BudgetYear = year; project.BudgetAmount = decimal.Parse(budget); project.BudgetType = (BudgetType)Enum.Parse(typeof(BudgetType), expenditure); project.CreateAction = new iSabaya.UserAction(SessionContext.User); project.StatusCategory = StatusCategory.Update; project.Status = Status.SaveDeail; SessionContext.Persist(project); tx.Commit(); SessionContext.Log(0, this.PageID, 0, MessageException.ProjectMessage.UpdateDetail, MessageException.Success()); } catch (Exception ex) { tx.Rollback(); SessionContext.LogButNotFlush(0, this.PageID, 0, MessageException.ProjectMessage.UpdateDetail, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Success = true, Message = "บันทึก ข้อมูลรายละเอียดโครงการ เรียบร้อย" }, JsonRequestBehavior.AllowGet)); }