/// <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())
                        {
                            result.Add(Mapper.Map(Context.SurveyMetaDatas.FirstOrDefault(x => x.SurveyId == Id)));
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw (ex);
                }
            }
            else
            {
                try
                {
                    using (var Context = DataObjectFactory.CreateContext())
                    {
                        result = Mapper.Map(Context.SurveyMetaDatas.ToList());
                    }
                }
                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);
        }
Exemplo n.º 2
0
        public List <OrganizationBO> GetOrganizationInfoForAdmin(int UserId, int UserRole)
        {
            List <OrganizationBO> result = new List <OrganizationBO>();


            try
            {
                using (var Context = DataObjectFactory.CreateContext())
                {
                    if (UserRole == 3)
                    {
                        var Query = from OrganizationTable in Context.Organizations
                                    from UserOrganizationTable in Context.UserOrganizations

                                    where UserOrganizationTable.OrganizationID == OrganizationTable.OrganizationId &&
                                    UserOrganizationTable.UserID == UserId &&
                                    UserOrganizationTable.RoleId >= 2 &&
                                    UserOrganizationTable.Active == true &&
                                    OrganizationTable.IsEnabled == true
                                    select OrganizationTable;

                        var DataRow = Query.Distinct();
                        foreach (var Row in DataRow)
                        {
                            result.Add(Mapper.Map(Row));
                        }

                        return(result);
                    }
                    else
                    {
                        var Query = from OrganizationTable in Context.Organizations
                                    from UserOrganizationTable in Context.UserOrganizations

                                    where UserOrganizationTable.OrganizationID == OrganizationTable.OrganizationId &&
                                    UserOrganizationTable.UserID == UserId &&
                                    UserOrganizationTable.RoleId == 2 &&
                                    UserOrganizationTable.Active == true &&
                                    OrganizationTable.IsEnabled == true
                                    select OrganizationTable;

                        var DataRow = Query.Distinct();
                        foreach (var Row in DataRow)
                        {
                            result.Add(Mapper.Map(Row));
                        }

                        return(result);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public UserBO GetCurrentUser(int UserId)
        {
            UserBO Result = new UserBO();

            using (var Context = DataObjectFactory.CreateContext())
            {
                Result = Mapper.MapToUserBO(Context.Users.Single(x => x.UserID == UserId));
            }
            return(Result);
        }
        public bool UpdateUserOrganization(UserBO User, OrganizationBO OrgBO)
        {
            UserOrganization UserOrganizationEntity = Mapper.ToUserOrganizationEntity(User, OrgBO);

            using (var Context = DataObjectFactory.CreateContext())
            {
                UserOrganizationEntity.UserID = User.UserId;
                Context.AddToUserOrganizations(UserOrganizationEntity);
                Context.SaveChanges();

                return(true);
            }
        }
        public List <SurveyInfoBO> GetSurveyInfoByOrgKey(string SurveyId, string Okey)
        {
            List <SurveyInfoBO> result = new List <SurveyInfoBO>();

            List <SurveyMetaData> responseList = new List <SurveyMetaData>();

            int OrganizationId = 0;

            try
            {
                using (var Context = DataObjectFactory.CreateContext())
                {
                    var Query = (from response in Context.Organizations
                                 where response.OrganizationKey == Okey
                                 select response).SingleOrDefault();

                    if (Query != null)
                    {
                        OrganizationId = Query.OrganizationId;
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            if (!string.IsNullOrEmpty(SurveyId))
            {
                try
                {
                    Guid Id = new Guid(SurveyId);
                    using (var Context = DataObjectFactory.CreateContext())
                    {
                        responseList.Add(Context.SurveyMetaDatas.FirstOrDefault(x => x.SurveyId == Id && x.OrganizationId == OrganizationId));
                        if (responseList[0] != null)
                        {
                            result = Mapper.Map(responseList);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw (ex);
                }
            }

            return(result);
        }
        public bool IsUserExistsInOrganizaion(UserBO User, OrganizationBO OrgBO)
        {
            var Context   = DataObjectFactory.CreateContext();
            var UserQuery = from userorganization in Context.UserOrganizations
                            where userorganization.UserID == User.UserId && userorganization.OrganizationID == OrgBO.OrganizationId
                            select userorganization;
            bool Result = false;

            foreach (var user in UserQuery)
            {
                Result = true;
            }

            return(Result);
        }
        public bool GetExistingUser(UserBO User)
        {
            var Context   = DataObjectFactory.CreateContext();
            var UserQuery = from user in Context.Users
                            where user.UserName == User.UserName && user.LastName == User.LastName && user.EmailAddress == User.EmailAddress
                            select user;
            bool Result = false;

            foreach (var user in UserQuery)
            {
                Result = true;
            }

            return(Result);
        }
 public bool UpdateUserPassword(UserBO User)
 {
     try
     {
         var Context = DataObjectFactory.CreateContext();
         var user    = Context.Users.Single(a => a.UserName == User.UserName);
         user.PasswordHash  = User.PasswordHash;
         user.ResetPassword = User.ResetPassword;
         Context.SaveChanges();
         return(true);
     }
     catch (Exception ex)
     {
         return(false);
     }
 }
        public void InsertConnectionString(DbConnectionStringBO ConnectionString)
        {
            try
            {
                using (var Context = DataObjectFactory.CreateContext())
                {
                    Context.usp_AddDatasource(ConnectionString.DatasourceServerName, ConnectionString.DatabaseType, ConnectionString.InitialCatalog, ConnectionString.PersistSecurityInfo, ConnectionString.DatabaseUserID, ConnectionString.SurveyId, ConnectionString.Password);

                    Context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public UserBO GetUser(UserBO User)
        {
            var Context   = DataObjectFactory.CreateContext();
            var UserQuery = from user in Context.Users
                            where user.UserName == User.UserName && user.PasswordHash == User.PasswordHash
                            select user;
            UserBO Result = new UserBO();

            foreach (var user in UserQuery)
            {
                Result = Mapper.MapToUserBO(user);
                return(Result);
            }

            return(null);
        }
Exemplo n.º 11
0
        public UserBO GetUserByEmail(UserBO User)
        {
            var Context   = DataObjectFactory.CreateContext();
            var UserQuery = from Users in Context.Users
                            where Users.EmailAddress == User.EmailAddress
                            select Users;
            UserBO Result = new UserBO();

            foreach (var user in UserQuery)
            {
                Result = Mapper.MapToUserBO(user);
                return(Result);
            }

            return(null);
        }
Exemplo n.º 12
0
        public bool IsUserExistsInOrganization(string OrgKey, int UserId)
        {
            var Context   = DataObjectFactory.CreateContext();
            var UserQuery = from userorganization in Context.UserOrganizations
                            join organization in Context.Organizations on userorganization.OrganizationID equals organization.OrganizationId
                            where userorganization.UserID == UserId && organization.OrganizationKey == OrgKey
                            select userorganization;
            bool Result = false;

            foreach (var user in UserQuery)
            {
                Result = true;
            }

            return(Result);
        }
        public void InsertFormdefaultSettings(string FormId, bool IsSqlProject, List <string> ControlsNameList)
        {
            try
            {
                //Delete old columns
                using (var Context = DataObjectFactory.CreateContext())
                {
                    Guid Id = new Guid(FormId);
                    IQueryable <ResponseDisplaySetting> ColumnList = Context.ResponseDisplaySettings.Where(x => x.FormId == Id);


                    foreach (var item in ColumnList)
                    {
                        Context.ResponseDisplaySettings.DeleteObject(item);
                    }
                    Context.SaveChanges();
                }
                // Adding new columns
                List <string> ColumnNames = new List <string>();
                if (!IsSqlProject)
                {
                    ColumnNames = MetaDaTaColumnNames();
                }
                else
                {
                    ColumnNames = ControlsNameList;
                }
                int i = 1;
                foreach (string Column in ColumnNames)
                {
                    using (var Context = DataObjectFactory.CreateContext())
                    {
                        ResponseDisplaySetting SettingEntity = Mapper.Map(FormId, i, Column);

                        Context.AddToResponseDisplaySettings(SettingEntity);

                        Context.SaveChanges();
                    }
                    i++;
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Inserts a new Organization.
        /// </summary>
        /// <remarks>
        /// Following insert, Organization object will contain the new identifier.
        /// </remarks>
        /// <param name="Organization">Organization.</param>
        public void InsertOrganization(OrganizationBO Organization)
        {
            try
            {
                using (var Context = DataObjectFactory.CreateContext())
                {
                    Organization OrganizationEntity = Mapper.ToEF(Organization);
                    Context.AddToOrganizations(OrganizationEntity);

                    Context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public List <UserBO> GetUserByFormId(string FormId)
        {
            Guid          id       = new Guid(FormId);
            List <UserBO> UserList = new List <UserBO>();
            UserBO        UserBO   = new UserBO();

            using (var Context = DataObjectFactory.CreateContext())
            {
                SurveyMetaData SelectedUserQuery = Context.SurveyMetaDatas.First(x => x.SurveyId == id);

                IQueryable <User> Users = SelectedUserQuery.Users.AsQueryable();
                foreach (User user in Users)
                {
                    UserList.Add(Mapper.MapToUserBO(user));
                }
            }
            return(UserList);
        }
        public UserBO GetUserByUserIdAndOrgId(UserBO User, OrganizationBO OrgBO)
        {
            var Context   = DataObjectFactory.CreateContext();
            var UserQuery = from Users in Context.Users
                            where Users.UserID == User.UserId
                            select Users;
            UserBO Result = new UserBO();

            foreach (var user in UserQuery)
            {
                Result = Mapper.MapToUserBO(user);

                var _User = Context.UserOrganizations.Where(x => x.UserID == user.UserID && x.OrganizationID == OrgBO.OrganizationId).Single();
                Result.IsActive = _User.Active;
                Result.Role     = _User.RoleId;
            }
            return(Result);
        }
Exemplo n.º 17
0
        public bool InsertOrganization(OrganizationBO Organization, int UserId, int RoleId)
        {
            try
            {
                UserOrganization UserOrganizationEntity = Mapper.ToUserOrganizationEntity(Organization.IsEnabled, UserId, RoleId, Organization);
                using (var Context = DataObjectFactory.CreateContext())
                {
                    Context.AddToUserOrganizations(UserOrganizationEntity);

                    Context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public List <SurveyInfoBO> GetChildInfoByParentId(string ParentFormId, int ViewId)
        {
            List <SurveyInfoBO> result = new List <SurveyInfoBO>();

            try
            {
                Guid Id = new Guid(ParentFormId);

                using (var Context = DataObjectFactory.CreateContext())
                {
                    result.Add(Mapper.Map(Context.SurveyMetaDatas.FirstOrDefault(x => x.ParentId == Id && x.ViewId == ViewId)));
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            return(result);
        }
        public SurveyInfoBO GetParentInfoByChildId(string ChildId)
        {
            SurveyInfoBO result = new SurveyInfoBO();

            try
            {
                Guid Id = new Guid(ChildId);

                using (var Context = DataObjectFactory.CreateContext())
                {
                    result = Mapper.Map(Context.SurveyMetaDatas.FirstOrDefault(x => x.SurveyId == Id));
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            return(result);
        }
        public int GetUserHighestRole(int UserId)
        {
            int HighestRole = 0;

            try
            {
                using (var Context = DataObjectFactory.CreateContext())
                {
                    var Rows = Context.UserOrganizations.Where(x => x.UserID == UserId && x.Active == true && x.Organization.IsEnabled == true);
                    HighestRole = Rows.Max(x => x.RoleId);
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }


            return(HighestRole);
        }
        public List <UserBO> GetAdminsBySelectedOrgs(FormSettingBO FormSettingBO, string formId)
        {
            List <UserBO> AdminList = new List <UserBO>();

            using (var Context = DataObjectFactory.CreateContext())
            {
                foreach (var item in FormSettingBO.SelectedOrgList)
                {
                    int OrgId = int.Parse(item.Value);

                    var users = Context.UserOrganizations.Where(x => x.RoleId == 2 && x.OrganizationID == OrgId && x.Active == true);

                    foreach (var user in users)
                    {
                        AdminList.Add(Mapper.MapToUserBO(user.User, user.RoleId));
                    }
                }
            }
            return(AdminList);
        }
        public List <string> GetAllColumnNames(string FormId)
        {
            Guid Id = new Guid(FormId);

            try
            {
                using (var Context = DataObjectFactory.CreateContext())
                {
                    List <string> Columns = (from c in Context.SurveyMetaDataTransforms
                                             where c.SurveyId == Id &&
                                             (c.FieldTypeId != 2 && c.FieldTypeId != 20 && c.FieldTypeId != 3 && c.FieldTypeId != 21 && c.FieldTypeId != 4 && c.FieldTypeId != 13) //filter non-data fields.
                                             orderby c.FieldName
                                             select c.FieldName).ToList();
                    return(Columns);
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public List <SurveyInfoBO> GetFormsHierarchyIdsByRootId(string RootId)
        {
            List <SurveyInfoBO> result = new List <SurveyInfoBO>();

            List <string> list = new List <string>();

            try
            {
                Guid Id = new Guid(RootId);

                using (var Context = DataObjectFactory.CreateContext())
                {
                    IQueryable <SurveyMetaData> Query = Context.SurveyMetaDatas.Where(x => x.SurveyId == Id).Traverse(x => x.SurveyMetaData1).AsQueryable();
                    result = Mapper.Map(Query);
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            return(result);
        }
        public bool HasDraftRecords(string FormId)
        {
            try
            {
                Guid Id = new Guid(FormId);
                bool _HasDraftRecords = false;
                using (var Context = DataObjectFactory.CreateContext())
                {
                    var DraftRecords = Context.SurveyResponses.Where(x => x.SurveyId == Id && x.IsDraftMode == true);
                    if (DraftRecords.Count() > 0)
                    {
                        _HasDraftRecords = true;
                    }
                }

                return(_HasDraftRecords);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Updates a Organization.
        /// </summary>
        /// <param name="Organization">Organization.</param>
        public bool UpdateOrganization(OrganizationBO Organization)
        {
            ////Update Survey
            try
            {
                using (var Context = DataObjectFactory.CreateContext())
                {
                    var Query = from org in Context.Organizations
                                where org.OrganizationKey == Organization.OrganizationKey
                                select org;

                    var SuperAdminChkQry = from usrorg in Context.UserOrganizations
                                           join org in Context.Organizations
                                           on usrorg.OrganizationID equals org.OrganizationId
                                           where org.OrganizationKey == Organization.OrganizationKey && usrorg.RoleId > 2
                                           select usrorg;

                    var DataRow = Query.Single();

                    var SuperAdminRow = SuperAdminChkQry.FirstOrDefault();

                    DataRow.Organization1 = Organization.Organization;

                    if (SuperAdminRow != null && DataRow.IsEnabled != Organization.IsEnabled)
                    {
                        return(false);
                    }

                    DataRow.IsEnabled = Organization.IsEnabled;
                    Context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public FormInfoBO GetFormByFormId(string FormId)
        {
            FormInfoBO FormInfoBO = new FormInfoBO();

            try
            {
                Guid Id = new Guid(FormId);

                using (var Context = DataObjectFactory.CreateContext())
                {
                    SurveyMetaData SurveyMetaData = Context.SurveyMetaDatas.Single(x => x.SurveyId == Id);
                    FormInfoBO = Mapper.ToFormInfoBO(SurveyMetaData);
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }



            return(FormInfoBO);
        }
        public void UpdateConnectionString(DbConnectionStringBO ConnectionString)
        {
            try
            {
                using (var Context = DataObjectFactory.CreateContext())
                {
                    var Query = from DataSource in Context.EIDatasources
                                where DataSource.SurveyId == ConnectionString.SurveyId
                                select DataSource;

                    var DataRow = Query.Single();
                    DataRow = Mapper.Map(ConnectionString);

                    Context.AddToEIDatasources(DataRow);

                    Context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public void DeleteDraftRecords(string FormId)
        {
            Guid NewId = new Guid(FormId);

            try
            {
                using (var Context = DataObjectFactory.CreateContext())
                {
                    List <string> Ids = new List <string>();


                    List <SurveyInfoBO> result = GetFormsHierarchyIdsByRootId(FormId);
                    foreach (var item in result)
                    {
                        Ids.Add(item.SurveyId);
                    }

                    Ids.Reverse();


                    //Get Root


                    foreach (var Id in Ids)
                    {
                        Guid _Id = new Guid(Id);
                        Context.SurveyResponses.Where(x => x.SurveyId == _Id && x.IsDraftMode == true).ToList().ForEach(Context.SurveyResponses.DeleteObject);

                        Context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public bool UpdateUserInfo(UserBO User, OrganizationBO OrgBO)
        {
            try
            {
                using (var Context = DataObjectFactory.CreateContext())
                {
                    User user = Context.Users.First(x => x.UserID == User.UserId);
                    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 List <UserBO> GetUserByOrgId(int OrgId)
        {
            List <UserBO> UserList = new List <UserBO>();

            using (var Context = DataObjectFactory.CreateContext())
            {
                var SelectedUserQuery = from UserOrg in Context.UserOrganizations
                                        join user in Context.Users on UserOrg.UserID equals user.UserID
                                        where UserOrg.OrganizationID == OrgId
                                        select user;
                foreach (var user in SelectedUserQuery)
                {
                    var UserBO = Mapper.MapToUserBO(user);
                    var User   = Context.UserOrganizations.Where(x => x.UserID == user.UserID && x.OrganizationID == OrgId).Single();
                    UserBO.IsActive = User.Active;
                    UserBO.Role     = User.RoleId;
                    UserList.Add(UserBO);
                }
            }



            return(UserList);
        }