コード例 #1
0
        public IEnumerable <UserAwardDTO> Load()
        {
            using (StreamReader read = new StreamReader(file.FullName))
            {
                string       line       = null;
                UserAwardDTO user_award = new UserAwardDTO();
                while (true)
                {
                    line = read.ReadLine();
                    if (line == "UserAward:")
                    {
                        user_award.UserId  = Guid.Parse(read.ReadLine());
                        user_award.AwardId = Guid.Parse(read.ReadLine());
                        UsersAwards.Add(user_award);
                        user_award = new UserAwardDTO();
                    }

                    else
                    {
                        break;
                    }
                }
                return(UsersAwards);
            }
        }
コード例 #2
0
        public UserAwardDTO Get(UserAwardDTO note)
        {
            try
            {
                return(dal_user_award.Get(note));
            }

            catch (Exception e)
            {
                Logger.Logger.WriteLog(e);
                throw e;
            }
        }
コード例 #3
0
        public bool Delete(UserAwardDTO note)
        {
            try
            {
                return(dal_user_award.Delete(note));
            }

            catch (Exception e)
            {
                Logger.Logger.WriteLog(e);
                throw e;
            }
        }
コード例 #4
0
 public bool Delete(UserAwardDTO note)
 {
     using (var connection = new SqlConnection(connectionString))
     {
         var delete_user_award = connection.CreateCommand();
         delete_user_award.CommandText = $"DELETE FROM dbo.UserAward WHERE UserId = @UserId AND AwardId = @AwardId";
         delete_user_award.Parameters.AddWithValue("@UserId", note.UserId);
         delete_user_award.Parameters.AddWithValue("@AwardId", note.AwardId);
         connection.Open();
         var result = delete_user_award.ExecuteNonQuery();
         return(result > 0);
     }
 }
コード例 #5
0
 public bool Create(UserAwardDTO note)
 {
     using (var connection = new SqlConnection(connectionString))
     {
         var add_award = connection.CreateCommand();
         add_award.CommandText = $"INSERT INTO dbo.UserAward (UserId, AwardId) VALUES (@UserId, @AwardId)";
         add_award.Parameters.AddWithValue("@UserId", note.UserId);
         add_award.Parameters.AddWithValue("@AwardId", note.AwardId);
         connection.Open();
         var result = add_award.ExecuteNonQuery();
         return(result > 0);
     }
 }
コード例 #6
0
 public bool Create(UserAwardDTO note)
 {
     try
     {
         UsersAwards.Add(note);
         return(true);
     }
     catch (Exception e)
     {
         Logger.Logger.WriteLog(e);
         throw new NullReferenceException("нет записи", e);
     }
 }
コード例 #7
0
        public UserAwardDTO Get(UserAwardDTO user_award)
        {
            try
            {
                UserAwardDTO temp = new UserAwardDTO();
                foreach (var item in UsersAwards)
                {
                    if (item == user_award)
                    {
                        temp = item;
                        break;
                    }
                }
                return(temp);
            }

            catch (Exception e)
            {
                Logger.Logger.WriteLog(e);
                throw e;
            }
        }
コード例 #8
0
        public bool Delete(UserAwardDTO user_award)
        {
            try
            {
                foreach (var item in UsersAwards)
                {
                    if (item == user_award)
                    {
                        UsersAwards.Remove(item);
                        break;
                    }
                }

                return(true);
            }

            catch (Exception e)
            {
                Logger.Logger.WriteLog(e);
                throw new NullReferenceException("нет данной записи", e);
            }
        }