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 GetMinistry(int id) { try { Organization organization = Organization.Find(SessionContext, id); MinistryViewModel ministry = new MinistryViewModel { ID = organization.ID, Code = organization.Code, Name = organization.CurrentName.Name.GetValue(SessionContext.CurrentLanguage.Code) }; if (organization == null) { SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Get, MessageException.Null("The static method Find return null, ID : " + id)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true, ministry }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Get, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetAnnounces() { IList <Announce> announces = null; IList <AnnounceViewModel> announceViewModels = null; try { announces = Announce.GetAll(SessionContext); announceViewModels = announces.Select(x => new AnnounceViewModel { Id = x.ID, HeadLine = x.HeadLine, Content = x.Content }).ToList(); } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Gets, MessageException.Fail(ex.Message)); } return(Json(announceViewModels, 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 GetUser(long id = 0) { UserViewModel userViewModel = null; try { iSabaya.SelfAuthenticatedUser user = SessionContext.PersistenceSession.Get <iSabaya.SelfAuthenticatedUser>(id); if (user == null) { SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Get, MessageException.Null("Get SelfAuthenticatedUser return null, ID : " + id)); } else { userViewModel = new UserViewModel { Id = user.ID, IdCard = user.Person.OfficialIDNo, FirstNameTh = user.Person.CurrentName.FirstName.GetValue("th-TH"), LastNameTh = user.Person.CurrentName.LastName.GetValue("th-TH"), FirstNameEn = user.Person.CurrentName.FirstName.GetValue("en-US"), LastNameEn = user.Person.CurrentName.LastName.GetValue("en-US"), PhoneCenter = user.PhoneCenter == null ? "" : user.PhoneCenter + user.PhoneCenterTo, PhoneDirect = user.PhoneDirect == null ? "" : user.PhoneDirect, Mobile = user.MobilePhoneNumber == null ? "" : user.MobilePhoneNumber, Email = user.EMailAddress, Address = user.Address, Status = user.UserRoles[0].Role.Code == "User" ? user.UserRoles[0].Role.Description.Split(',')[0] : user.UserRoles[0].Role.Description, //IsOnline = false, IsDelete = user.IsEffective, Department = new DepartmentViewModel { ID = user.OrgUnit.ID, Name = user.OrgUnit.CurrentName.Name.GetValue("th-TH"), Code = user.OrgUnit.Code, Ministry = new MinistryViewModel { ID = user.OrgUnit.OrganizationParent.ID, Name = user.OrgUnit.OrganizationParent.CurrentName.Name.GetValue("th-TH"), Code = user.OrgUnit.OrganizationParent.Code, }, }, }; } } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Get, MessageException.Fail(ex.Message)); } return(Json(userViewModel, JsonRequestBehavior.AllowGet)); }
public JsonResult GetUsers() { IList <UserViewModel> userModels = null; try { DateTime now = DateTime.Now; IList <iSabaya.SelfAuthenticatedUser> users = SessionContext.PersistenceSession.QueryOver <iSabaya.SelfAuthenticatedUser>().List(); //Get userSession is SingoutTS is nax date mean use is not singout IList <iSabaya.UserSession> userSessions = SessionContext.PersistenceSession .QueryOver <iSabaya.UserSession>() .Where(x => x.SessionPeriod.To == iSabaya.TimeInterval.MaxDate) .List(); userModels = users.Where(x => x.EffectivePeriod.From <= now && x.EffectivePeriod.To >= now) .Select(u => new UserViewModel { Id = u.ID, //No = no++, IdCard = u.Person.OfficialIDNo, FirstNameTh = u.Person.CurrentName.FirstName.GetValue("th-TH"), LastNameTh = u.Person.CurrentName.LastName.GetValue("th-TH"), IsOnline = userSessions.Any(s => s.User.ID == u.ID), IsDelete = !u.IsEffective, Address = u.Address, Status = u.UserRoles[0].Role.Code == "User" ? u.UserRoles[0].Role.Description.Split(',')[0] : u.UserRoles[0].Role.Description, Department = new DepartmentViewModel { ID = u.OrgUnit.ID, Name = u.OrgUnit.CurrentName.Name.GetValue("th-TH"), Code = u.OrgUnit.Code, Ministry = new MinistryViewModel { ID = u.OrgUnit.OrganizationParent.ID, Name = u.OrgUnit.OrganizationParent.CurrentName.Name.GetValue("th-TH"), Code = u.OrgUnit.OrganizationParent.Code, }, }, IsActive = !u.IsDisable, }).ToList(); //Use is UserReport Session["userReport"] = userModels; } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Gets, MessageException.Fail(ex.Message)); } return(Json(userModels, JsonRequestBehavior.AllowGet)); }
public JsonResult Search(string idcard = "", string firstname = "", string lastname = "", long ministryId = 0L, int role = 0, int status = 0, string isDelete = "") { IList <UserViewModel> userViewModels = null; try { DateTime now = DateTime.Now; bool isDel = isDelete == "2"; IList <iSabaya.SelfAuthenticatedUser> users = SessionContext.PersistenceSession.QueryOver <iSabaya.SelfAuthenticatedUser>().List(); if (!string.IsNullOrEmpty(idcard)) { users = users.Where(x => x.Person.OfficialIDNo == idcard).ToList(); } if (!string.IsNullOrEmpty(firstname)) { users = users.Where(x => x.Person.CurrentName.FirstName.Values.Any(f => f.Value == firstname)).ToList(); } if (!string.IsNullOrEmpty(lastname)) { users = users.Where(x => x.Person.CurrentName.LastName.Values.Any(l => l.Value == lastname)).ToList(); } if (ministryId > 0) { users = users.Where(x => x.Organization.ID == ministryId).ToList(); } if (role > 0) { users = users.Where(x => x.UserRoles[0].Role.Id == role).ToList(); } if (status > 0) { users = users.Where(x => x.IsDisable == (status == 1 ? false : true)).ToList(); } if (!string.IsNullOrEmpty(isDelete)) { if (isDel) { users = users.Where(x => x.EffectivePeriod.From < now && x.EffectivePeriod.To < now).ToList(); } else { users = users.Where(x => x.EffectivePeriod.From <= now && x.EffectivePeriod.To >= now).ToList(); } } //Get userSession is SingoutTS is nax date mean use is not singout IList <iSabaya.UserSession> userSessions = SessionContext.PersistenceSession .QueryOver <iSabaya.UserSession>() .Where(x => x.SessionPeriod.To == iSabaya.TimeInterval.MaxDate) .List(); userViewModels = users.Select(u => new UserViewModel { Id = u.ID, IdCard = u.Person.OfficialIDNo, FirstNameTh = u.Person.CurrentName.FirstName.GetValue("th-TH"), LastNameTh = u.Person.CurrentName.LastName.GetValue("th-TH"), IsOnline = userSessions.Any(s => s.User.ID == u.ID), IsDelete = !u.IsEffective, Status = "", IsActive = !u.IsDisable, Department = new DepartmentViewModel { ID = u.OrgUnit.ID, Name = u.OrgUnit.CurrentName.Name.GetValue("th-TH"), Code = u.OrgUnit.Code, Ministry = new MinistryViewModel { ID = u.OrgUnit.OrganizationParent.ID, Name = u.OrgUnit.OrganizationParent.CurrentName.Name.GetValue("th-TH"), Code = u.OrgUnit.OrganizationParent.Code, }, }, }).ToList(); } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.UserMessage.Search, MessageException.Fail(ex.Message)); } return(Json(userViewModels, JsonRequestBehavior.AllowGet)); }
public JsonResult GetStrategics() { IList <Strategic> strategics = null; IList <StrategicViewModel> strategicViewModels = null; try { strategics = Strategic.GetEffectives(SessionContext); strategicViewModels = strategics.Select(x => new StrategicViewModel { ID = x.ID, Name = x.Name, }).ToList(); } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.StrategicMessage.Gets, MessageException.Fail(ex.Message)); } return(Json(strategicViewModels, 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 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 ActionResult Error500() { if (SessionContext.User != null) { SessionContext.Log(0, PageID, 0, MessageException.InvalidPageMessage.Error500, MessageException.Fail(SessionContext.User.ID.ToString())); } else { SessionContext.Log(0, PageID, 0, MessageException.InvalidPageMessage.Error500, MessageException.Fail("Anonymous user")); } Response.StatusCode = 200; return(View("Error500")); }
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 GetProjects(string year, string budget, string status) { try { IList <Project> projects = null; var model = new List <ProjectViewModel>(); projects = SessionContext .PersistenceSession .QueryOver <Project>() .Where(x => x.OrgUnit.ID == SessionContext.User.OrgUnit.ID).List(); if (projects.Any()) { if (!string.IsNullOrEmpty(year)) { projects = projects.Where(x => x.BudgetYear == year).ToList(); } if (!string.IsNullOrEmpty(budget)) { projects = projects.Where(x => x.BudgetAmount == decimal.Parse(budget)).ToList(); } switch (status) { case "Incomplete": model = projects .Where(x => x.StatusCategory <= StatusCategory.IncompleteAnswerR) .ToList() .Select(p => new ProjectViewModel { ID = p.ID, Name = p.Name, NameLink = p.ProjectIncompleteUrl(ApplicationName), BudgetType = p.BudgetTypeName, ProjectType = p.ProjectCategoryName, Budget = p.BudgetAmount.ToString(Formetter.MoneyFormat), Year = p.BudgetYear, LastUpdate = p.CreateAction.Timestamp.ToString(Formetter.DateTimeFormat), }).ToList(); break; case "completeUnsign": model = projects .Where(x => x.StatusCategory == StatusCategory.CompleteUnsign || x.StatusCategory == StatusCategory.Update) .ToList() .Select(p => new ProjectViewModel { ID = p.ID, Name = p.Name, NameLink = p.ProjectCompleteUnsignUrl(ApplicationName), BudgetType = p.BudgetTypeName, ProjectType = p.ProjectCategoryName, Budget = p.BudgetAmount.ToString(Formetter.MoneyFormat), Year = p.BudgetYear, LastUpdate = p.CreateAction.Timestamp.ToString(Formetter.DateTimeFormat), }).ToList(); break; case "completeSign": model = projects .Where(x => x.StatusCategory == StatusCategory.CompleteSign) .ToList() .Select(p => new ProjectViewModel { ID = p.ID, Name = p.Name, NameLink = p.ProjectCompleteSignUrl(ApplicationName), BudgetType = p.BudgetTypeName, ProjectType = p.ProjectCategoryName, Budget = p.BudgetAmount.ToString(Formetter.MoneyFormat), Year = p.BudgetYear, LastUpdate = p.CreateAction.Timestamp.ToString(Formetter.DateTimeFormat), RiskResult = p.RiskBox }).ToList(); break; case "unRisk": model = projects .Where(x => x.StatusCategory == StatusCategory.UnRisk) .ToList() .Select(p => new ProjectViewModel { ID = p.ID, Name = p.Name, NameLink = p.ProjectUnRiskUrl(ApplicationName), BudgetType = p.BudgetTypeName, ProjectType = p.ProjectCategoryName, Budget = p.BudgetAmount.ToString(Formetter.MoneyFormat), Year = p.BudgetYear, LastUpdate = p.CreateAction.Timestamp.ToString(Formetter.DateTimeFormat), }).ToList(); break; default: break; } } return(Json(new { Success = true, model }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { SessionContext.LogButNotFlush( 0, this.PageID, 0, MessageException.ProjectMessage.GetIncomplete, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, 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 GetMinistries() { IList <MinistryViewModel> ministry = null; try { IList <Organization> organizations = Organization.List(SessionContext); ministry = organizations .Select(x => new MinistryViewModel { ID = x.ID, Code = x.Code, Name = x.CurrentName.Name.GetValue(SessionContext.CurrentLanguage.Code) }).ToList(); } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.MinistryMessage.Gets, MessageException.Fail(ex.Message)); } return(Json(ministry, 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 GetStrategic(long id) { try { Strategic strategic = Strategic.Get(SessionContext, id); if (strategic == null) { SessionContext.Log(0, this.pageID, 0, MessageException.StrategicMessage.Get, MessageException.Null("The static method Get return null, ID : " + id)); return(Json(new { Success = false, Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } StrategicViewModel strategicViewModel = new StrategicViewModel { ID = strategic.ID, Name = strategic.Name, }; return(Json(new { Success = true, strategicViewModel }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.StrategicMessage.Get, MessageException.Fail(ex.Message)); return(Json(new { Success = false, Message = MessageException.Error }, 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 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 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 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 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 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 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 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 Get(long id) { DepartmentViewModel department = null; try { OrgUnit orgUnit = OrgUnit.Find(SessionContext, id); if (orgUnit == null) { SessionContext.Log(0, this.pageID, 0, MessageException.DepartmentMessage.Get, MessageException.Null("The static method Find return null, ID : " + id)); } department = new DepartmentViewModel { ID = orgUnit.ID, Code = orgUnit.Code, Name = orgUnit.CurrentName.Name.GetValue("th-TH"), Ministry = new MinistryViewModel { ID = orgUnit.OrganizationParent.ID, Code = orgUnit.OrganizationParent.Code, Name = orgUnit.OrganizationParent.CurrentName.Name.GetValue(SessionContext.CurrentLanguage.Code) } }; } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.DepartmentMessage.Get, MessageException.Fail(ex.Message)); } return(Json(department, JsonRequestBehavior.AllowGet)); }
public JsonResult GetAnnounce(long id) { try { Announce announce = Announce.Get(SessionContext, id); if (announce == null) { SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Get, MessageException.Null("The static method Get return null, ID : " + id)); return(Json(new { Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } return(Json(new AnnounceViewModel { Id = announce.ID, HeadLine = announce.HeadLine, Content = announce.Content }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.AnnounceMessage.Get, MessageException.Fail(ex.Message)); return(Json(new { Message = MessageException.Error }, JsonRequestBehavior.AllowGet)); } }
public JsonResult GetDepartments(long ministryId) { IList <DepartmentViewModel> departmentViewModels = null; try { IList <OrgUnit> orgUnits = SessionContext.PersistenceSession .QueryOver <OrgUnit>() .Where(x => x.OrganizationParent.ID == ministryId) .List(); departmentViewModels = orgUnits.Select(x => new DepartmentViewModel { ID = x.ID, Code = x.Code, Name = x.CurrentName.Name.GetValue("th-TH"), Ministry = new MinistryViewModel { ID = x.OrganizationParent.ID, Code = x.OrganizationParent.Code, Name = x.OrganizationParent.CurrentName.Name.GetValue(SessionContext.CurrentLanguage.Code) } }).ToList(); } catch (Exception ex) { SessionContext.Log(0, this.pageID, 0, MessageException.DepartmentMessage.Gets, MessageException.Fail(ex.Message)); } return(Json(departmentViewModels, 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 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)); }