public static session CreateSession(user objUser)
        {
            try
            {
                using (ModelContext objContext = new ModelContext())
                {
                    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 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);
        }