コード例 #1
0
        public bool DeleteItemByKey(int key)
        {
            try
            {
                using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
                {
                    CLoginDataDto loginData = context.CLoginDatasDto.Where(l => l.PersonID == key).FirstOrDefault();
                    if (loginData == null)
                    {
                        log.Info("Can't delete loginData because it doesn't exist in database (personId = {0})", key);
                        return(false);
                    }

                    context.CLoginDatasDto.Remove(loginData);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure while trying to delete loginData (PersonId = {1}). Message: {0}", ex.Message, key);
                return(false);
            }

            return(true);
        }
コード例 #2
0
        public bool UpdateItem(CLoginDataDto item)
        {
            try
            {
                using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
                {
                    CLoginDataDto loginData = context.CLoginDatasDto.Where(l => l.PersonID == item.PersonID).FirstOrDefault();
                    if (loginData == null)
                    {
                        log.Info("Can't update loginData because it doesn't exist in database (personId = {0})", item.PersonID);
                        return(false);
                    }

                    loginData.email        = item.email;
                    loginData.Username     = item.Username;
                    loginData.PasswordHash = item.PasswordHash;
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure while trying to update loginData (PersonId = {1}). Message: {0}", ex.Message, item.PersonID);
                return(false);
            }

            return(true);
        }
コード例 #3
0
 public CLoginDataDto FindLoginDataByUsername(string username)
 {
     try
     {
         SpendingHelperDBEntities connection = CSConnectionPool.GetConnection();
         CLoginDataDto            loginDto   = connection.CLoginDatasDto.FirstOrDefault(l => l.Username.Equals(username));
         return(loginDto);
     }
     catch (Exception ex)
     {
         log.Error(ex, "Some error occure while trying to FindLoginDataByUsername. Message: {0}", ex.Message);
         return(null);
     }
 }
コード例 #4
0
        public bool AddItem(CLoginDataDto item)
        {
            try
            {
                using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
                {
                    context.CLoginDatasDto.Add(item);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                log.Error(ex, "Some error occure while trying to add loginData into DB. Message: {0}", ex.Message);
                return(false);
            }

            return(true);
        }
コード例 #5
0
 public CLoginDataDto FindLoginDataByEmail(string email)
 {
     try
     {
         //SpendingHelperDBEntities context = CSConnectionPool.GetConnection();
         using (SpendingHelperDBEntities context = new SpendingHelperDBEntities())
         {
             CLoginDataDto loginDto = (from login in context.CLoginDatasDto
                                       where login.email.ToLower().Equals(email.ToLower())
                                       select login).FirstOrDefault();
             return(loginDto);
         }
     }
     catch (Exception ex)
     {
         log.Error(ex, "Some error occure while trying to FindLoginDataByEmail. Message: {0}", ex.Message);
         return(null);
     }
 }