Esempio n. 1
0
        static public void FavoriteAdd(byte companyID, short userID, byte favoriteCompanyID, short favoriteUserID, byte companyCount)
        {
            try
            {
                using (CSMessengerContext dbContext = new CSMessengerContext())
                {
                    UserFavorite NewUserFavorite = new UserFavorite();
                    NewUserFavorite.CompanyID         = companyID;
                    NewUserFavorite.UserID            = userID;
                    NewUserFavorite.FavoriteCompanyID = favoriteCompanyID;
                    NewUserFavorite.FavoriteUserID    = favoriteUserID;

                    dbContext.UserFavorite.Add(NewUserFavorite);
                    dbContext.SaveChanges();

                    string companyAbbreviation = dbContext.Company.Find(favoriteCompanyID).Abbreviation;
                    string userName            = dbContext.User.Find(favoriteCompanyID, favoriteUserID).Name;
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException.InnerException.HResult == -2146232060)
                {
                    MessageBox.Show("Este Contacto ya está en la lista de Favoritos.", My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    MessageBox.Show(string.Format("Error al agregar el Contacto a la lista de Favoritos.{0}{0}Error #{1}: {2}", System.Environment.NewLine, ex.HResult, ex.Message), My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 2
0
 static public void FavoriteRemove(byte companyID, short userID, byte favoriteCompanyID, short favoriteUserID)
 {
     try
     {
         CSMessengerContext dbContext            = new CSMessengerContext();
         UserFavorite       UserFavoriteToRemove = dbContext.UserFavorite.Find(companyID, userID, favoriteCompanyID, favoriteUserID);
         dbContext.UserFavorite.Remove(UserFavoriteToRemove);
         dbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         MessageBox.Show(string.Format("Error al quitar el Contacto a la lista de Favoritos.{0}{0}Error #{1}: {2}", System.Environment.NewLine, ex.HResult, ex.Message), My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 3
0
        public bool CheckUser(short userID, out string userName)
        {
            // Check if User exists in Company database and gets it's name
            if (GetUserFromCompanyDatabase(userID) == false)
            {
                userName = null;
                return(false);
            }

            // Check if User exists in local database
            mUser = mdbContext.User.Find(mCompany.CompanyID, userID);
            if (mUser == null)
            {
                try
                {
                    // Doesn't exist, so add it
                    mUser           = new User();
                    mUser.CompanyID = mCompany.CompanyID;
                    mUser.UserID    = userID;
                    mUser.Name      = mUserNameOnCompanyDB;
                    mUser.Semaphore = 0;
                    mUser.IsActive  = true;
                    mdbContext.User.Add(mUser);

                    // Update the Company Semaphore to advice others clients to refresh Company Users list
                    mCompany.Semaphore = DateTime.Now.Millisecond;

                    mdbContext.SaveChanges();

                    userName = mUser.Name;
                    return(true);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format("Error agregando el Usuario a la base de datos.{0}{0}Error #{1}: {2}", System.Environment.NewLine, ex.HResult, ex.Message), My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    userName = null;
                    return(false);
                }
            }
            else
            {
                // Exists, so check data
                if (mUser.Name != mUserNameOnCompanyDB)
                {
                    try
                    {
                        mUser.Name = mUserNameOnCompanyDB;

                        // Update the Company Semaphore to advice others clients to refresh Company Users list
                        mCompany.Semaphore = DateTime.Now.Millisecond;

                        mdbContext.SaveChanges();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(string.Format("Error actualizando el Nombre del Usuario a la base de datos.{0}{0}Error #{1}: {2}", System.Environment.NewLine, ex.HResult, ex.Message), My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        userName = null;
                        return(false);
                    }
                }

                userName = mUser.Name;
                return(true);
            }
        }