public List <UserBO> GetOrgAdminsByFormId(string FormId) { List <UserBO> BoList = new List <UserBO>(); Dictionary <int, string> GetOrgAdmins = new Dictionary <int, string>(); Guid Id = new Guid(FormId); try { using (var Context = DataObjectFactory.CreateContext()) { SurveyMetaData Response = Context.SurveyMetaDatas.First(x => x.SurveyId == Id); var _Org = new HashSet <int>(Response.Organizations.Select(x => x.OrganizationId)); var Orgs = Context.Organizations.Where(t => _Org.Contains(t.OrganizationId)).ToList(); foreach (var Org in Orgs) { var AdminList = Context.UserOrganizations.Where(x => x.OrganizationID == Org.OrganizationId && x.RoleId == 2 && x.Active == true); foreach (var Admin in AdminList) { UserBO UserBO = new UserBO(); UserBO.EmailAddress = Admin.User.EmailAddress; UserBO.UserId = Admin.User.UserID; BoList.Add(UserBO); } } } } catch (Exception ex) { throw (ex); } return(BoList); }
public void UpdateFormMode(FormInfoBO formInfoBO, FormSettingBO formSettingBO = null) { try { Guid id = new Guid(formInfoBO.FormId); //Update Form Mode using (var context = DataObjectFactory.CreateContext()) { var query = from response in context.SurveyMetaDatas where response.SurveyId == id select response; var dataRow = query.Single(); dataRow.IsDraftMode = formInfoBO.IsDraftMode; dataRow.IsShareable = formInfoBO.IsShareable; dataRow.DataAccessRuleId = formInfoBO.DataAccesRuleId; context.SaveChanges(); } } catch (Exception ex) { throw (ex); } }
public Dictionary <int, string> GetOrgAdmins(Dictionary <int, string> SelectedOrgList) { Dictionary <int, string> GetOrgAdmins = new Dictionary <int, string>(); int i = 0; try { foreach (var org in SelectedOrgList) { using (var Context = DataObjectFactory.CreateContext()) { int OrgId = int.Parse(org.Value); var AdminList = Context.UserOrganizations.Where(x => x.OrganizationID == OrgId && x.RoleId == 2 && x.Active == true).ToList(); foreach (var item in AdminList) { GetOrgAdmins.Add(i, item.User.EmailAddress); i++; } } } } catch (Exception ex) { throw (ex); } return(GetOrgAdmins); }
public bool UpdateUserInfo(UserBO User, OrganizationBO OrgBO) { try { using (var Context = DataObjectFactory.CreateContext()) { User user = Context.Users.First(x => x.UserID == User.UserId); // user.UserName = User.UserName; user.EmailAddress = User.EmailAddress; user.FirstName = User.FirstName; user.LastName = User.LastName; UserOrganization UserOrganization = Context.UserOrganizations.First(x => x.OrganizationID == OrgBO.OrganizationId && x.UserID == User.UserId); UserOrganization.RoleId = User.Role; UserOrganization.Active = User.IsActive; Context.SaveChanges(); } return(true); } catch (Exception ex) { throw (ex); } }
public SurveyInfoBO GetDashboardSurveyInfo(string surveyid) { SurveyInfoBO SurveyInfoBO = new SurveyInfoBO(); using (var Context = DataObjectFactory.CreateContext()) { Guid Id = new Guid(surveyid); var Query = from survey in Context.SurveyMetaDatas where survey.SurveyId == Id select new { survey.IsSQLProject, survey.IsDraftMode, survey.ClosingDate, survey.StartDate, survey.DateCreated, survey.SurveyName }; foreach (var item in Query) { SurveyInfoBO.SurveyName = item.SurveyName; SurveyInfoBO.DateCreated = item.DateCreated; SurveyInfoBO.ClosingDate = item.ClosingDate; SurveyInfoBO.StartDate = item.StartDate; SurveyInfoBO.IsDraftMode = item.IsDraftMode; SurveyInfoBO.IsSqlProject = (bool)item.IsSQLProject; } } return(SurveyInfoBO); }
public string GetAdminOrgKeyByEmail(string UserEmail) { var OrgKey = ""; try { using (var Context = DataObjectFactory.CreateContext()) { var Query = (from response in Context.Admins where response.AdminEmail == UserEmail select new { response.Organization.OrganizationKey }).Distinct(); foreach (var item in Query) { OrgKey = item.OrganizationKey.ToString(); break; } } } catch (Exception ex) { throw (ex); } return(OrgKey); }
public List <AdminBO> GetAdminEmails() { List <AdminBO> AdminBO = new List <AdminBO>(); try { using (var Context = DataObjectFactory.CreateContext()) { var Query = (from response in Context.Admins select new { response.AdminEmail }).Distinct(); var DataRow = Query.Distinct(); foreach (var Row in DataRow) { AdminBO.Add(Mapper.MapAdminEmail(Row.AdminEmail)); } } } catch (Exception ex) { throw (ex); } return(AdminBO); }
public AdminBO GetAdminEmailByAdminId(string AdminEmail) { AdminBO AdminBO = new AdminBO(); try { using (var Context = DataObjectFactory.CreateContext()) { var Query = (from response in Context.Admins where response.AdminEmail == AdminEmail select new { response.AdminEmail }).Distinct(); var DataRow = Query.Distinct(); foreach (var Row in DataRow) { AdminBO = Mapper.MapAdminEmail(Row.AdminEmail); } } } catch (Exception ex) { throw (ex); } return(AdminBO); }
public int GetOrganizationId(string OrgKey) { int OrganizationId = -1; try { using (var Context = DataObjectFactory.CreateContext()) { var Query = (from response in Context.Organizations where response.OrganizationKey == OrgKey select response).SingleOrDefault(); if (Query != null) { OrganizationId = Query.OrganizationId; } } } catch (Exception ex) { throw (ex); } return(OrganizationId); }
public Dictionary <int, string> GetOrgAdmins(Dictionary <int, string> selectedOrgList) { Dictionary <int, string> orgAdmins = new Dictionary <int, string>(); try { int i = 0; foreach (var org in selectedOrgList) { using (var context = DataObjectFactory.CreateContext()) { int orgId = int.Parse(org.Value); var adminList = context.UserOrganizations.Where(x => x.OrganizationID == orgId && x.RoleId == Roles.Administrator && x.Active == true).ToList(); foreach (var item in adminList) { orgAdmins.Add(i++, item.User.EmailAddress); } } } } catch (Exception ex) { throw (ex); } return(orgAdmins); }
public List <OrganizationBO> GetOrganizationsByUserId(int UserId) { List <OrganizationBO> result = new List <OrganizationBO>(); try { using (var Context = DataObjectFactory.CreateContext()) { var Query = from OrganizationTable in Context.Organizations from UserOrganizationTable in Context.UserOrganizations where UserOrganizationTable.OrganizationID == OrganizationTable.OrganizationId && UserOrganizationTable.UserID == UserId && UserOrganizationTable.Active == true && OrganizationTable.IsEnabled == true select OrganizationTable; var DataRow = Query; foreach (var Row in DataRow) { result.Add(Mapper.Map(Row)); } return(result); } } catch (Exception ex) { throw (ex); } }
public List <OrganizationBO> GetOrganizationInfo() { List <OrganizationBO> OrganizationBO = new List <OrganizationBO>(); try { using (var Context = DataObjectFactory.CreateContext()) { var Query = (from response in Context.Organizations select response); var DataRow = Query.Distinct(); foreach (var Row in DataRow) { OrganizationBO.Add(Mapper.Map(Row)); } } } catch (Exception ex) { throw (ex); } return(OrganizationBO); }
/// <summary> /// Inserts a new SurveyInfo. /// </summary> /// <remarks> /// Following insert, SurveyInfo object will contain the new identifier. /// </remarks> /// <param name="SurveyInfo">SurveyInfo.</param> public void InsertSurveyInfo(SurveyInfoBO SurveyInfo) { int OrganizationId = 0; try { using (var Context = DataObjectFactory.CreateContext()) { //retrieve OrganizationId based on OrganizationKey using (var ContextOrg = DataObjectFactory.CreateContext()) { string OrgKey = Epi.Web.Common.Security.Cryptography.Encrypt(SurveyInfo.OrganizationKey.ToString()); OrganizationId = ContextOrg.Organizations.FirstOrDefault(x => x.OrganizationKey == OrgKey).OrganizationId; } SurveyInfo.TemplateXMLSize = RemoveWhitespace(SurveyInfo.XML).Length; SurveyInfo.DateCreated = DateTime.Now; SurveyInfo.LastUpdate = DateTime.Now; SurveyInfo.IsSqlProject = SurveyInfo.IsSqlProject; var SurveyMetaDataEntity = Mapper.Map(SurveyInfo); SurveyMetaDataEntity.OrganizationId = OrganizationId; Context.SurveyMetaDatas.Add(SurveyMetaDataEntity); Context.SaveChanges(); } } catch (Exception ex) { throw (ex); } }
/// <summary> /// Updates a SurveyInfo. /// </summary> /// <param name="SurveyInfo">SurveyInfo.</param> public void UpdateSurveyInfo(SurveyInfoBO SurveyInfo) { try { Guid Id = new Guid(SurveyInfo.SurveyId); //Update Survey using (var Context = DataObjectFactory.CreateContext()) { //var Query = from response in Context.SurveyMetaDatas // where response.SurveyId == Id // select response; //var DataRow = Query.Single(); //DataRow = Mapper.ToEF(SurveyInfo); SurveyMetaData Row = Context.SurveyMetaDatas.First(x => x.SurveyId == Id); Row.IsSQLProject = SurveyInfo.IsSqlProject; Row.TemplateXML = SurveyInfo.XML; Row.IsDraftMode = SurveyInfo.IsDraftMode; Row.IsShareable = SurveyInfo.IsShareable; Row.DataAccessRuleId = SurveyInfo.DataAccessRuleId; Context.SaveChanges(); } } catch (Exception ex) { throw (ex); } }
public List <StateBO> GetStateList() { List <StateBO> List = new List <StateBO>(); try { using (var Context = DataObjectFactory.CreateContext()) { var Query = from state in Context.States select state; var DataRow = Query; foreach (var Row in DataRow) { List.Add(Mapper.Map(Row)); } } } catch (Exception ex) { throw (ex); } return(List); }
public List <ReportInfoBO> GetReport(string ReportID) { List <ReportInfoBO> ReportInfoBOList = new List <ReportInfoBO>(); try { ReportInfoBO ReportInfoBO = new ReportInfoBO(); var reportid = Guid.Parse(ReportID); using (var Context = DataObjectFactory.CreateContext()) { var Query = Context.SurveyReportsInfoes.Where(x => x.ReportId == reportid);//.OrderBy(x=>x.GadgetNumber); foreach (var item in Query) { ReportInfoBO = Mapper.ToReportInfoBO(item); ReportInfoBOList.Add(ReportInfoBO); } } return(ReportInfoBOList); } catch (Exception ex) { throw (ex); } }
public FormSettingBO GetFormSettings() { FormSettingBO formSettingBO = new FormSettingBO(); Dictionary <int, string> dataAccessRuleIds = new Dictionary <int, string>(); Dictionary <string, string> dataAccessRuleDescription = new Dictionary <string, string>(); int selectedDataAccessRuleId = -1;; using (var context = DataObjectFactory.CreateContext()) { try { //// Available DataAccess Rule Ids list IQueryable <DataAccessRule> ruleIDs = context.DataAccessRules.ToList().AsQueryable(); foreach (var rule in ruleIDs) { dataAccessRuleIds.Add(rule.RuleId, rule.RuleName); dataAccessRuleDescription.Add(rule.RuleName, rule.RuleDescription); } formSettingBO.SelectedDataAccessRule = selectedDataAccessRuleId; formSettingBO.DataAccessRuleDescription = dataAccessRuleDescription; formSettingBO.DataAccessRuleIds = dataAccessRuleIds; } catch (Exception ex) { throw (ex); } } return(formSettingBO); }
public void UpdateResponseGridColumnNames(FormSettingBO FormSettingBO, string FormId) { Guid Id = new Guid(FormId); try { using (var Context = DataObjectFactory.CreateContext()) { IQueryable <ResponseDisplaySetting> ColumnList = Context.ResponseDisplaySettings.Where(x => x.FormId == Id); //Delete old columns foreach (var item in ColumnList) { Context.ResponseDisplaySettings.DeleteObject(item); } Context.SaveChanges(); //insert new columns ResponseDisplaySetting ResponseDisplaySettingEntity = new ResponseDisplaySetting(); foreach (var item in FormSettingBO.ResponseGridColumnNameList) { ResponseDisplaySettingEntity = Mapper.ToColumnName(item, Id); Context.AddToResponseDisplaySettings(ResponseDisplaySettingEntity); } Context.SaveChanges(); } } catch (Exception ex) { throw (ex); } }
public void SoftDeleteForm(string formId) { // TODO: Refactor to remove dependency on SurveyMetadatas Guid Id = new Guid(formId); try { using (var context = DataObjectFactory.CreateContext()) { var query = from response in context.SurveyMetaDatas where response.SurveyId == Id select response; var dataRow = query.Single(); dataRow.ParentId = Id; context.SaveChanges(); } } catch (Exception ex) { throw (ex); } }
public List <OrganizationBO> GetOrganizationInfoByOrgKey(string gOrgKeyEncrypted) { List <OrganizationBO> OrganizationBO = new List <OrganizationBO>(); try { using (var Context = DataObjectFactory.CreateContext()) { var Query = (from response in Context.Organizations where response.OrganizationKey == gOrgKeyEncrypted && response.IsEnabled == true select response); var DataRow = Query; foreach (var Row in DataRow) { OrganizationBO.Add(Mapper.Map(Row)); } } } catch (Exception ex) { throw (ex); } return(OrganizationBO); }
public List <CacheDependencyBO> GetCacheDependencyInfo(List <string> surveyKeys) { List <CacheDependencyBO> result = new List <CacheDependencyBO>(); if (surveyKeys.Count > 0) { try { foreach (string key in surveyKeys) { Guid guid = new Guid(key); using (var Context = DataObjectFactory.CreateContext()) { SurveyMetaData surveyMetaDatas = Context.SurveyMetaDatas.FirstOrDefault(x => x.SurveyId == guid); CacheDependencyBO cacheDependencyBO = Mapper.MapDependency(surveyMetaDatas); result.Add(cacheDependencyBO); } } } catch (Exception ex) { throw (ex); } } return(result); }
/// <summary> /// Gets a specific Organization. /// </summary> /// <param name="OrganizationId">Unique Organization identifier.</param> /// <returns>Organization.</returns> public List <OrganizationBO> GetOrganizationKeys(string OrganizationName) { List <OrganizationBO> OrganizationBO = new List <OrganizationBO>(); try { using (var Context = DataObjectFactory.CreateContext()) { var Query = from response in Context.Organizations where response.Organization1 == OrganizationName select response; var DataRow = Query; foreach (var Row in DataRow) { OrganizationBO.Add(Mapper.Map(Row)); } } } catch (Exception ex) { throw (ex); } return(OrganizationBO); }
public FormSettingBO GetFormSettings() { FormSettingBO FormSettingBO = new FormSettingBO(); Dictionary <int, string> DataAccessRuleIds = new Dictionary <int, string>(); Dictionary <string, string> DataAccessRuleDescription = new Dictionary <string, string>(); int selectedDataAccessRuleId = -1;; var Context = DataObjectFactory.CreateContext(); try { //// Available DataAccess Rule Ids list IQueryable <DataAccessRule> RuleIDs = Context.DataAccessRules.ToList().AsQueryable(); foreach (var Rule in RuleIDs) { DataAccessRuleIds.Add(Rule.RuleId, Rule.RuleName); DataAccessRuleDescription.Add(Rule.RuleName, Rule.RuleDescription); } FormSettingBO.SelectedDataAccessRule = selectedDataAccessRuleId; FormSettingBO.DataAccessRuleDescription = DataAccessRuleDescription; FormSettingBO.DataAccessRuleIds = DataAccessRuleIds; } catch (Exception ex) { throw (ex); } return(FormSettingBO); }
public OrganizationBO GetOrganizationByOrgId(int OrganizationId) { OrganizationBO OrganizationBO = new OrganizationBO(); try { using (var Context = DataObjectFactory.CreateContext()) { var Query = from response in Context.Organizations where response.OrganizationId == OrganizationId select response; if (Query.Count() > 0) { OrganizationBO = Mapper.Map(Query.SingleOrDefault()); } else { return(null); } } } catch (Exception ex) { throw (ex); } return(OrganizationBO); }
public bool InsertUser(UserBO User, OrganizationBO OrgBO) { try { User.UGuid = Guid.NewGuid(); using (var Context = DataObjectFactory.CreateContext()) { var Org = Context.Organizations.Where(x => x.OrganizationId == OrgBO.OrganizationId).Single(); Context.Organizations.Attach(Org); Context.Users.Add(Mapper.ToUserEntity(User)); UserOrganization UserOrganizationEntity = Mapper.ToUserOrganizationEntity(User, OrgBO); Context.UserOrganizations.Add(UserOrganizationEntity); Context.SaveChanges(); } return(true); } catch (Exception ex) { throw (ex); } }
public OrganizationBO GetOrganizationInfoByKey(string key) { OrganizationBO OrganizationBO = new OrganizationBO(); try { using (var Context = DataObjectFactory.CreateContext()) { var Query = (from response in Context.Organizations where response.OrganizationKey == key select response); if (Query.Count() > 0) { OrganizationBO = Mapper.Map(Query.SingleOrDefault()); } else { return(null); } } } catch (Exception ex) { throw (ex); } return(OrganizationBO); }
public void UpDateFormMode(FormInfoBO FormInfoBO) { try { Guid Id = new Guid(FormInfoBO.FormId); //Update Form Mode using (var Context = DataObjectFactory.CreateContext()) { var Query = from response in Context.SurveyMetaDatas where response.SurveyId == Id select response; var DataRow = Query.Single(); DataRow.IsDraftMode = FormInfoBO.IsDraftMode; DataRow.IsShareable = FormInfoBO.IsShareable; DataRow.DataAccessRuleId = FormInfoBO.DataAccesRuleId; Context.SaveChanges(); } } catch (Exception ex) { throw (ex); } }
public List <AdminBO> GetAdminInfoByOrgKey(string gOrgKeyEncrypted) { List <AdminBO> AdminList = new List <AdminBO>(); int OrgId = 0; int AdminOrgId = 0; try { using (var Context = DataObjectFactory.CreateContext()) { var OrgQuery = (from response in Context.Organizations where response.OrganizationKey == gOrgKeyEncrypted select new { response.OrganizationId }).First(); OrgId = OrgQuery.OrganizationId; var AdminOrgQuery = (from response in Context.Organizations where response.IsHostOrganization == true select new { response.OrganizationId }).First(); AdminOrgId = AdminOrgQuery.OrganizationId; var AdminQuery = (from response in Context.Admins where response.OrganizationId == OrgId && response.IsActive == true && response.Notify == true select new { response }); var AdminQuery1 = (from response in Context.Admins where response.OrganizationId == AdminOrgId && response.IsActive == true && response.Notify == true select new { response }); foreach (var row in AdminQuery) { AdminBO AdminBO = new Common.BusinessObject.AdminBO(); AdminBO.AdminEmail = row.response.AdminEmail; AdminBO.IsActive = row.response.IsActive; AdminList.Add(AdminBO); } foreach (var row in AdminQuery1) { AdminBO AdminBO = new Common.BusinessObject.AdminBO(); AdminBO.AdminEmail = row.response.AdminEmail; AdminBO.IsActive = row.response.IsActive; AdminList.Add(AdminBO); } } } catch (Exception ex) { throw (ex); } return(AdminList); }
public void UpdateSettingsList(FormSettingBO formSettingBO, string formId, int CurrentOrg = -1) { Guid id = new Guid(formId); try { using (var context = DataObjectFactory.CreateContext()) { SurveyMetaData response = context.SurveyMetaDatas.First(x => x.SurveyId == id); //Remove old Users var userHashSet = new HashSet <string>(response.Users.Select(x => x.UserName)); var users = context.Users.Where(t => userHashSet.Contains(t.UserName)).ToList(); foreach (User user in users) { if (user.UserOrganizations.Where(x => x.OrganizationID == CurrentOrg).Count() > 0) { response.Users.Remove(user); } } context.SaveChanges(); //insert new users foreach (var item in formSettingBO.AssignedUserList) { User User = context.Users.FirstOrDefault(x => x.UserName == item.Value); response.Users.Add(User); } context.SaveChanges(); //Remove old Orgs var orgHashSet = new HashSet <int>(response.Organizations.Select(x => x.OrganizationId)); var orgs = context.Organizations.Where(t => orgHashSet.Contains(t.OrganizationId)).ToList(); foreach (Organization org in orgs) { response.Organizations.Remove(org); } context.SaveChanges(); //insert new Orgs List <User> orgAdmins = new List <User>(); foreach (var item in formSettingBO.SelectedOrgList) { int orgId = int.Parse(item.Value); Organization org = context.Organizations.FirstOrDefault(x => x.OrganizationId == orgId); response.Organizations.Add(org); } context.SaveChanges(); } } catch (Exception ex) { throw (ex); } }
/// <summary> /// Gets SurveyInfo based on a list of ids /// </summary> /// <param name="SurveyInfoId">Unique SurveyInfo identifier.</param> /// <returns>SurveyInfo.</returns> public List <SurveyInfoBO> GetSurveyInfo(List <string> SurveyInfoIdList, int PageNumber = -1, int PageSize = -1) { List <SurveyInfoBO> result = new List <SurveyInfoBO>(); if (SurveyInfoIdList.Count > 0) { try { foreach (string surveyInfoId in SurveyInfoIdList.Distinct()) { Guid Id = new Guid(surveyInfoId); using (var Context = DataObjectFactory.CreateContext()) { var response = Context.SurveyMetaDatas.FirstOrDefault(x => x.SurveyId == Id); result.Add(Mapper.Map(response)); } } } catch (Exception ex) { throw (ex); } } else { try { using (var Context = DataObjectFactory.CreateContext()) { result.Add(Mapper.Map(Context.SurveyMetaDatas.First())); } } catch (Exception ex) { throw (ex); } } // remove the items to skip // remove the items after the page size if (PageNumber > 0 && PageSize > 0) { result.Sort(CompareByDateCreated); // remove the items to skip if (PageNumber * PageSize - PageSize > 0) { result.RemoveRange(0, PageSize); } if (PageNumber * PageSize < result.Count) { result.RemoveRange(PageNumber * PageSize, result.Count - PageNumber * PageSize); } } return(result); }