public static date FindOrAddDate(DateTime objDateTime)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    date objDate = objContext.dates.Where(d => d.date_value__date == objDateTime.Date).FirstOrDefault();

                    if (objDate == null)
                    {
                        Guid objGuid;
                        do
                        {
                            objGuid = Guid.NewGuid();
                        } while (objContext.dates.Where(d => d.date_uuid__uniqueidentifier == objGuid).Count() > 0);

                        objContext.dates.Add(new date()
                        {
                            date_uuid__uniqueidentifier = objGuid, date_value__date = objDateTime
                        });
                        objContext.SaveChanges();

                        return(objContext.dates.Where(d => d.date_uuid__uniqueidentifier == objGuid).FirstOrDefault());
                    }
                    else
                    {
                        return(objDate);
                    }
                }
            }
            catch { }

            return(null);
        }
예제 #2
0
        public static resource Add(string stName, byte byExtension, string stDescription, byte[] byaValue, string stExternalUrlName)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    Guid objGuid;
                    do
                    {
                        objGuid = Guid.NewGuid();
                    } while (FindByUUID(objGuid) != null);

                    resource objResource;

                    objResource = new resource()
                    {
                        reso_uuid__uniqueidentifier      = objGuid,
                        reso_name__nvarchar              = stName,
                        reso_extension__tinyint          = byExtension,
                        reso_description__nvarchar       = stDescription,
                        reso_value__varbinary            = byaValue,
                        reso_externalurlorname__nvarchar = stExternalUrlName,
                    };

                    objContext.resources.Add(objResource);

                    objContext.SaveChanges();

                    return(objContext.resources.Where(r => r.reso_uuid__uniqueidentifier == objResource.reso_uuid__uniqueidentifier).FirstOrDefault());
                }
            }
            catch { }

            return(null);
        }
        public static sbyte FindByUserNameOrEmailOrCellphoneWithExcludedUser(string stUserName, string stEmail, string stCellphone, user objUserSelected)
        {
            try
            {
                if (!string.IsNullOrEmpty(stUserName) || !string.IsNullOrEmpty(stEmail) || !string.IsNullOrEmpty(stCellphone))
                {
                    using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                    {
                        if (!string.IsNullOrEmpty(stUserName) && objContext.users.Where(u => u.user_username__nvarchar == stUserName && u.user_uuid__uniqueidentifier != objUserSelected.user_uuid__uniqueidentifier && u.user_uuid_root__uniqueidentifier == null && u.sess_uuid_deleted__uniqueidentifier == null).FirstOrDefault() != null)
                        {
                            return(1);
                        }
                        if (!string.IsNullOrEmpty(stEmail) && objContext.users.Where(u => u.user_email__nvarchar == stEmail && u.user_uuid__uniqueidentifier != objUserSelected.user_uuid__uniqueidentifier && u.user_uuid_root__uniqueidentifier == null && u.sess_uuid_deleted__uniqueidentifier == null).FirstOrDefault() != null)
                        {
                            return(2);
                        }
                        if (!string.IsNullOrEmpty(stCellphone) && objContext.users.Where(u => u.user_cellphone__nvarchar == stCellphone && u.user_uuid__uniqueidentifier != objUserSelected.user_uuid__uniqueidentifier && u.user_uuid_root__uniqueidentifier == null && u.sess_uuid_deleted__uniqueidentifier == null).FirstOrDefault() != null)
                        {
                            return(3);
                        }
                    }
                }
                else
                {
                    return(-1);
                }
            }
            catch { }

            return(0);
        }
        public static List <user> GetAllUsers()
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    return(objContext.users.Where(u => u.user_uuid_root__uniqueidentifier == null && u.sess_uuid_deleted__uniqueidentifier == null).ToList());
                }
            }
            catch { }

            return(null);
        }
        public static user FindByUserNameOrEmailOrCellphone(string stUserNameEmailCellphone)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    return(objContext.users.Where(u => (u.user_username__nvarchar == stUserNameEmailCellphone || u.user_email__nvarchar == stUserNameEmailCellphone || u.user_cellphone__nvarchar == stUserNameEmailCellphone) && u.user_uuid_root__uniqueidentifier == null && u.sess_uuid_deleted__uniqueidentifier == null).FirstOrDefault());
                }
            }
            catch { }

            return(null);
        }
        public static principalcompany Get()
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    return(objContext.principalcompanies.Where(p => (p.prco_uuid_root__uniqueidentifier == null)).FirstOrDefault());
                }
            }
            catch { }

            return(null);
        }
        public static preference FindByUUID(Guid objUUID)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    return(objContext.preferences.Where(p => p.user_uuid__uniqueidentifier == objUUID).FirstOrDefault());
                }
            }
            catch { }

            return(null);
        }
        public static country FindByCode(string stCode)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    return(objContext.countries.Where(c => c.coun_code__nvarchar == stCode).FirstOrDefault());
                }
            }
            catch { }

            return(null);
        }
        public static state FindByName(string stName, country objCountry)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    return(objContext.states.Where(s => s.stat_name__nvarchar == stName && s.coun_uuid__uniqueidentifier == objCountry.coun_uuid__uniqueidentifier).FirstOrDefault());
                }
            }
            catch { }

            return(null);
        }
예제 #10
0
        public static session FindSeassion(Guid objGuid)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    return(objContext.sessions.Where(s => s.sess_uuid__uniqueidentifier == objGuid).FirstOrDefault());
                }
            }
            catch { }

            return(null);
        }
        public static List <city> GetCities(state objState)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    return(objContext.cities.Where(c => c.stat_uuid__uniqueidentifier == objState.stat_uuid__uniqueidentifier).ToList());
                }
            }
            catch { }

            return(null);
        }
        public static city FindByName(string stName, state objState)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    return(objContext.cities.Where(c => c.city_name__nvarchar == stName && c.stat_uuid__uniqueidentifier == objState.stat_uuid__uniqueidentifier).FirstOrDefault());
                }
            }
            catch { }

            return(null);
        }
예제 #13
0
        public static resource FindByName(string stNameFile)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    return(objContext.resources.Where(r => r.reso_name__nvarchar == stNameFile).FirstOrDefault());
                }
            }
            catch { }

            return(null);
        }
 public static List <city> GetAll()
 {
     try
     {
         using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
         {
             return(objContext.cities.ToList());
         }
     }
     catch
     {
         return(null);
     }
 }
 public static int GetCountAllUsers()
 {
     try
     {
         using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
         {
             return(objContext.users.Count());
         }
     }
     catch
     {
         return(-1);
     }
 }
        public static List <state> GetMexicosStates()
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    return((from country in objContext.countries
                            join state in objContext.states on country.coun_uuid__uniqueidentifier equals state.coun_uuid__uniqueidentifier
                            where (country.coun_code__nvarchar == "MX")
                            select state).ToList());
                }
            }
            catch { }

            return(null);
        }
        public static DateTime GetServersDateAndTime()
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    SqlParameter objSqlParameter = new SqlParameter("@dateTime", "");

                    string vDate = objContext.Database.SqlQuery <string>("EXEC build_level000.proc_systemserver_getdatetime @dateTime", objSqlParameter).FirstOrDefault();

                    return(Convert.ToDateTime(vDate));
                }
            }
            catch { }

            return(new DateTime(2000, 1, 1).Date);
        }
예제 #18
0
        public static bool UpdateLastTimeSession(session objSessionExtternall)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    session  objSession  = objContext.sessions.Where(s => s.sess_uuid__uniqueidentifier == objSessionExtternall.sess_uuid__uniqueidentifier).FirstOrDefault();
                    DateTime objDateTime = Business.GetServersDateAndTime();
                    objSession.sess_lastactivity__time = new TimeSpan(objDateTime.Hour, objDateTime.Minute, objDateTime.Second);
                    objContext.SaveChanges();

                    return(true);
                }
            }
            catch { }

            return(false);
        }
        public static bool DisableToEdit(Guid objGuid, session objSession)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    principalcompany objPrincipalCompany = objContext.principalcompanies.Where(p => p.prco_uuid__uniqueidentifier == objGuid).FirstOrDefault();

                    if (objPrincipalCompany != null)
                    {
                        objPrincipalCompany.sess_uuid_used__uniqueidentifier = objSession.sess_uuid__uniqueidentifier;
                        objContext.SaveChanges();
                    }
                }
            }
            catch { }

            return(false);
        }
        public static bool DisableToEdit(Guid objGuid, session objSession)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    user objUser = objContext.users.Where(u => u.user_uuid__uniqueidentifier == objGuid).FirstOrDefault();

                    if (objUser != null)
                    {
                        objUser.sess_uuid_used__uniqueidentifier = objSession.sess_uuid__uniqueidentifier;
                        objContext.SaveChanges();
                    }
                }
            }
            catch { }

            return(false);
        }
예제 #21
0
        public static session CreateSession(user objUser)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    Guid objGuid;
                    do
                    {
                        objGuid = Guid.NewGuid();
                    } while (objContext.sessions.Where(s => s.sess_uuid__uniqueidentifier == objGuid).Count() > 0);

                    date objDate = BDate.FindOrAddDate(DateTime.Now);

                    session objSession;

                    objSession = new session()
                    {
                        sess_uuid__uniqueidentifier         = Guid.NewGuid(),
                        sess_starttime__time                = TimeSpan.Parse(DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second),
                        sess_lastactivity__time             = TimeSpan.Parse(DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second),
                        sess_ipbatch01__tinyint             = null,
                        sess_ipbatch02__tinyint             = null,
                        sess_ipbatch03__tinyint             = null,
                        sess_ipbatch04__tinyint             = null,
                        sess_extradata__nvarchar            = null,
                        date_uuid__uniqueidentifier         = objDate.date_uuid__uniqueidentifier,
                        user_uuid_created__uniqueidentifier = objUser.user_uuid__uniqueidentifier
                    };

                    objContext.sessions.Add(objSession);

                    objContext.SaveChanges();

                    return(objContext.sessions.Where(s => s.sess_uuid__uniqueidentifier == objSession.sess_uuid__uniqueidentifier).FirstOrDefault());
                }
            }
            catch { }

            return(null);
        }
        public static bool Remove(user objUser, session objSession)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    var vUser = objContext.users.Where(u => u.user_uuid__uniqueidentifier == objUser.user_uuid__uniqueidentifier && u.sess_uuid_used__uniqueidentifier == objSession.sess_uuid__uniqueidentifier).FirstOrDefault();

                    if (vUser != null)
                    {
                        vUser.sess_uuid_used__uniqueidentifier    = null;
                        vUser.sess_uuid_deleted__uniqueidentifier = objSession.sess_uuid__uniqueidentifier;

                        objContext.SaveChanges();

                        return(true);
                    }
                }
            }
            catch { }

            return(false);
        }
        public static bool Edit(
            principalcompany objPrincipalCompany,
            string stRfc,
            string stName,
            string stAddress,
            string stPhone,
            string stEmail,
            string stFacebookUrl,
            bool boDevelopmentMode,
            int inHoursBetweenBackups,
            int inDaysDeleteBackups,
            string stNamePicture,
            byte[] byaPicture,
            string stState,
            string stCity,
            session objSession)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    var vPreferencePrincipal = objContext.principalcompanies.Where(p => p.prco_uuid__uniqueidentifier == objPrincipalCompany.prco_uuid__uniqueidentifier).FirstOrDefault();

                    var vLastBranch = objContext.proc_principalcompany_findAllBranches(objPrincipalCompany.prco_uuid__uniqueidentifier).LastOrDefault();

                    // Add Preference
                    Guid objGuidPreferenceAux = Guid.NewGuid();
                    do
                    {
                        objGuidPreferenceAux = Guid.NewGuid();
                    } while (FindByUUID(objGuidPreferenceAux) != null);

                    principalcompany objPrincipalCompanyAux = new principalcompany()
                    {
                        prco_uuid__uniqueidentifier         = objGuidPreferenceAux,
                        prco_rfc__nvarchar                  = vPreferencePrincipal.prco_rfc__nvarchar,
                        prco_name__nvarchar                 = vPreferencePrincipal.prco_name__nvarchar,
                        prco_address__nvarchar              = vPreferencePrincipal.prco_address__nvarchar,
                        prco_phone__nvarchar                = vPreferencePrincipal.prco_phone__nvarchar,
                        prco_email__nvarchar                = vPreferencePrincipal.prco_email__nvarchar,
                        prco_facebook__nvarchar             = vPreferencePrincipal.prco_facebook__nvarchar,
                        prco_developmentmode__bit           = vPreferencePrincipal.prco_developmentmode__bit,
                        prco_hoursbetweenbackups__int       = vPreferencePrincipal.prco_hoursbetweenbackups__int,
                        prco_daysdeletbackups__int          = vPreferencePrincipal.prco_daysdeletbackups__int,
                        reso_uuid_logo__uniqueidentifier    = vPreferencePrincipal.reso_uuid_logo__uniqueidentifier,
                        city_uuid__uniqueidentifier         = vPreferencePrincipal.city_uuid__uniqueidentifier,
                        sess_uuid_used__uniqueidentifier    = null,
                        sess_uuid_created__uniqueidentifier = vPreferencePrincipal.sess_uuid_created__uniqueidentifier,
                        prco_uuid_root__uniqueidentifier    = vLastBranch.prco_uuid__uniqueidentifier
                    };
                    objContext.principalcompanies.Add(objPrincipalCompanyAux);

                    // Add City
                    Guid?objGuidCity = null;
                    if (!string.IsNullOrEmpty(stCity))
                    {
                        objGuidCity = BCity.FindByName(stCity, BState.FindByName(stState, BCountry.FindByCode("MX"))).city_uuid__uniqueidentifier;
                    }

                    // Add Resource
                    Guid?objGuidResource = null;
                    if (byaPicture != null && !string.IsNullOrEmpty(stNamePicture))
                    {
                        objGuidResource = BResource.Add(stNamePicture, 1, null, byaPicture, null).reso_uuid__uniqueidentifier;
                    }

                    vPreferencePrincipal.prco_rfc__nvarchar                  = stRfc;
                    vPreferencePrincipal.prco_name__nvarchar                 = stName;
                    vPreferencePrincipal.prco_address__nvarchar              = stAddress;
                    vPreferencePrincipal.prco_phone__nvarchar                = stPhone;
                    vPreferencePrincipal.prco_email__nvarchar                = stEmail;
                    vPreferencePrincipal.prco_facebook__nvarchar             = stFacebookUrl;
                    vPreferencePrincipal.prco_developmentmode__bit           = boDevelopmentMode;
                    vPreferencePrincipal.prco_hoursbetweenbackups__int       = inHoursBetweenBackups;
                    vPreferencePrincipal.prco_daysdeletbackups__int          = inDaysDeleteBackups;//vPreferencePrincipal.prco_timebetweenbackups__int = inTimeBetweenBackups > 0 ? inTimeBetweenBackups: null;
                    vPreferencePrincipal.reso_uuid_logo__uniqueidentifier    = objGuidResource;
                    vPreferencePrincipal.city_uuid__uniqueidentifier         = objGuidCity;
                    vPreferencePrincipal.sess_uuid_used__uniqueidentifier    = null;
                    vPreferencePrincipal.sess_uuid_created__uniqueidentifier = objSession.sess_uuid__uniqueidentifier;
                    vPreferencePrincipal.prco_uuid_root__uniqueidentifier    = null;

                    objContext.SaveChanges();

                    return(true);
                }
            }
            catch { }

            return(false);
        }
        public static bool FreeAllRegistersAssociatedWithThisUser(user objUser)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    // This is identcal like the next block but in Linq
                    //SELECT u.*FROM[build_level002].[session] AS s
                    //   INNER JOIN[build_level001].[user] AS u ON s.sess_uuid__uniqueidentifier = u.sess_uuid_used__uniqueidentifier
                    //   WHERE s.user_uuid_created__uniqueidentifier = '9C749C38-DD8F-4BAC-898B-896ACAE44A23'

                    bool boBand = false;

                    var query01 =
                        (from sessionQ in objContext.sessions
                         join userQ in objContext.users on sessionQ.sess_uuid__uniqueidentifier equals userQ.sess_uuid_used__uniqueidentifier
                         where sessionQ.user_uuid_created__uniqueidentifier == objUser.user_uuid__uniqueidentifier
                         select userQ)
                        .ToList();

                    if (query01.Count > 0)
                    {
                        foreach (var vItem in query01)
                        {
                            vItem.sess_uuid_used__uniqueidentifier = null;
                        }

                        boBand = true;
                    }

                    var query02 =
                        (from sessionQ in objContext.sessions
                         join principalcompanyQ in objContext.principalcompanies on sessionQ.sess_uuid__uniqueidentifier equals principalcompanyQ.sess_uuid_used__uniqueidentifier
                         where sessionQ.user_uuid_created__uniqueidentifier == objUser.user_uuid__uniqueidentifier
                         select principalcompanyQ)
                        .ToList();

                    if (query02.Count > 0)
                    {
                        foreach (var vItem in query02)
                        {
                            vItem.sess_uuid_used__uniqueidentifier = null;
                        }

                        boBand = true;
                    }

                    if (boBand)
                    {
                        objContext.SaveChanges();
                    }

                    //objContext.users
                    //    .Where(u => u.sess_uuid_used__uniqueidentifier == objUser.user_uuid__uniqueidentifier)
                    //    .ToList()
                    //    .ForEach(x => x.sess_uuid_used__uniqueidentifier = null);
                    //objContext.SaveChanges();

                    return(true);
                }
            }
            catch { }

            return(false);
        }
        public static bool Edit(
            user objUser,
            string stUsername,
            string stEmail,
            string stCellphone,
            string stPassword,
            string stFirstname,
            string stLastname,
            byte byRoleAccess,
            string stExtradata,
            string stNamePicture,
            byte[] byaPicture,
            DateTime objDateBirthday,
            string stState,
            string stCity,
            session objSession)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    var vUserPrincipal = objContext.users.Where(u => u.user_uuid__uniqueidentifier == objUser.user_uuid__uniqueidentifier).FirstOrDefault();

                    var vLastBranch = objContext.proc_user_findAllBranches(objUser.user_uuid__uniqueidentifier).LastOrDefault();

                    // Add User
                    Guid objGuidUserAux = Guid.NewGuid();
                    do
                    {
                        objGuidUserAux = Guid.NewGuid();
                    } while (FindByUUID(objGuidUserAux) != null);

                    user objUserAux = new user()
                    {
                        user_uuid__uniqueidentifier           = objGuidUserAux,
                        user_username__nvarchar               = vUserPrincipal.user_username__nvarchar,
                        user_email__nvarchar                  = vUserPrincipal.user_email__nvarchar,
                        user_cellphone__nvarchar              = vUserPrincipal.user_cellphone__nvarchar,
                        user_password__nvarchar               = vUserPrincipal.user_password__nvarchar,
                        user_firstname__nvarchar              = vUserPrincipal.user_firstname__nvarchar,
                        user_lastname__nvarchar               = vUserPrincipal.user_lastname__nvarchar,
                        user_roleaccess__tinyint              = vUserPrincipal.user_roleaccess__tinyint,
                        user_extradata__nvarchar              = vUserPrincipal.user_extradata__nvarchar,
                        reso_uuid_picture__uniqueidentifier   = vUserPrincipal.reso_uuid_picture__uniqueidentifier,
                        date_uuid_birthdate__uniqueidentifier = vUserPrincipal.date_uuid_birthdate__uniqueidentifier,
                        city_uuid__uniqueidentifier           = vUserPrincipal.city_uuid__uniqueidentifier,
                        sess_uuid_used__uniqueidentifier      = null,
                        sess_uuid_created__uniqueidentifier   = vUserPrincipal.sess_uuid_created__uniqueidentifier,
                        user_uuid_root__uniqueidentifier      = vLastBranch.user_uuid__uniqueidentifier,
                        sess_uuid_deleted__uniqueidentifier   = null
                    };
                    objContext.users.Add(objUserAux);

                    // Add Date
                    Guid?objGuidDate = null;
                    if (objDateBirthday.Year != DateTime.Now.Year)
                    {
                        objGuidDate = BDate.FindOrAddDate(objDateBirthday).date_uuid__uniqueidentifier;
                    }

                    // Add City
                    Guid?objGuidCity = null;
                    if (!string.IsNullOrEmpty(stCity))
                    {
                        objGuidCity = BCity.FindByName(stCity, BState.FindByName(stState, BCountry.FindByCode("MX"))).city_uuid__uniqueidentifier;
                    }

                    // Add Resource
                    Guid?objGuidResource = null;
                    if (byaPicture != null && !string.IsNullOrEmpty(stNamePicture))
                    {
                        objGuidResource = BResource.Add(stNamePicture, 1, null, byaPicture, null).reso_uuid__uniqueidentifier;
                    }

                    vUserPrincipal.user_username__nvarchar  = stUsername;
                    vUserPrincipal.user_email__nvarchar     = stEmail;
                    vUserPrincipal.user_cellphone__nvarchar = stCellphone;
                    vUserPrincipal.user_password__nvarchar  = stPassword != Preferences.GlobalTextToComparePasswords ? Tools.Encrypt(stPassword) : objUserAux.user_password__nvarchar;
                    //txtPassword.Text != Preferences.GlobalTextToComparePasswords ? Tools.Encrypt(txtPassword.Text) : objUserSelectedPrincipalItem.user_password__nvarchar,
                    //vUserPrincipal.user_password__nvarchar = Tools.GetDefaulHash(stPassword);
                    vUserPrincipal.user_firstname__nvarchar              = Tools.Encrypt(stFirstname);
                    vUserPrincipal.user_lastname__nvarchar               = Tools.Encrypt(stLastname);
                    vUserPrincipal.user_roleaccess__tinyint              = byRoleAccess;
                    vUserPrincipal.user_extradata__nvarchar              = stExtradata;
                    vUserPrincipal.reso_uuid_picture__uniqueidentifier   = objGuidResource;
                    vUserPrincipal.date_uuid_birthdate__uniqueidentifier = objGuidDate;
                    vUserPrincipal.city_uuid__uniqueidentifier           = objGuidCity;
                    vUserPrincipal.sess_uuid_used__uniqueidentifier      = null;
                    vUserPrincipal.sess_uuid_created__uniqueidentifier   = objSession.sess_uuid__uniqueidentifier;
                    vUserPrincipal.user_uuid_root__uniqueidentifier      = null;
                    vUserPrincipal.sess_uuid_deleted__uniqueidentifier   = null;

                    objContext.SaveChanges();

                    return(true);
                }
            }
            catch { }

            return(false);
        }
        public static user Add(
            string stUsername,
            string stEmail,
            string stCellphone,
            string stPassword,
            string stFirstname,
            string stLastname,
            byte byRoleAccess,
            string stExtradata,
            string stNamePicture,
            byte[] byaPicture,
            DateTime objDateBirthday,
            string stState,
            string stCity,
            session objSessionCreator)
        {
            try
            {
                using (straad_generaldesktopapplication_pcpcpcpc_001Entities objContext = new straad_generaldesktopapplication_pcpcpcpc_001Entities())
                {
                    // Add Date
                    Guid?objGuidDate = null;
                    if (objDateBirthday.Year != DateTime.Now.Year)
                    {
                        objGuidDate = BDate.FindOrAddDate(objDateBirthday).date_uuid__uniqueidentifier;
                    }

                    // Add City
                    Guid?objGuidCity = null;
                    if (!string.IsNullOrEmpty(stCity))
                    {
                        objGuidCity = BCity.FindByName(stCity, BState.FindByName(stState, BCountry.FindByCode("MX"))).city_uuid__uniqueidentifier;
                    }

                    // Add Resource
                    Guid?objGuidResource = null;
                    if (byaPicture != null && !string.IsNullOrEmpty(stNamePicture))
                    {
                        objGuidResource = BResource.Add(stNamePicture, 1, null, byaPicture, null).reso_uuid__uniqueidentifier;
                    }

                    // Add User
                    Guid objGuidUser = Guid.NewGuid();
                    do
                    {
                        objGuidUser = Guid.NewGuid();
                    } while (FindByUUID(objGuidUser) != null);

                    objContext.users.Add(new user()
                    {
                        user_uuid__uniqueidentifier           = objGuidUser,
                        user_username__nvarchar               = stUsername,
                        user_email__nvarchar                  = stEmail,
                        user_cellphone__nvarchar              = stCellphone,
                        user_password__nvarchar               = Tools.GetDefaulHash(stPassword),
                        user_firstname__nvarchar              = Tools.Encrypt(stFirstname),
                        user_lastname__nvarchar               = Tools.Encrypt(stLastname),
                        user_roleaccess__tinyint              = byRoleAccess,
                        user_extradata__nvarchar              = stExtradata,
                        reso_uuid_picture__uniqueidentifier   = objGuidResource,
                        date_uuid_birthdate__uniqueidentifier = objGuidDate,
                        city_uuid__uniqueidentifier           = objGuidCity,
                        sess_uuid_used__uniqueidentifier      = null,
                        sess_uuid_created__uniqueidentifier   = objSessionCreator.sess_uuid__uniqueidentifier,
                        user_uuid_root__uniqueidentifier      = null,
                        sess_uuid_deleted__uniqueidentifier   = null
                    });

                    objContext.SaveChanges();

                    return(objContext.users.Where(u => u.user_uuid__uniqueidentifier == objGuidUser).FirstOrDefault());
                }
            }
            catch { }

            return(null);
        }