Example #1
0
 public void Add(Award value)
 {
     using (var connection = new SqlConnection(_connectionString))
     {
         var cmd = connection.CreateCommand();
         cmd.CommandType = CommandType.StoredProcedure;
         cmd.CommandText = "addAward";
         cmd.Parameters.AddWithValue(@"Title", value.Title);
         var id = new SqlParameter
         {
             DbType        = DbType.Int32,
             ParameterName = "@ID",
             Direction     = ParameterDirection.Output
         };
         cmd.Parameters.Add(id);
         connection.Open();
         cmd.ExecuteNonQuery();
     }
 }
Example #2
0
        public void Save(Award award)
        {
            using (var connection = new NpgsqlConnection())
            {
                connection.Open();
                var sqlCommand = new NpgsqlCommand("sp_add_award", connection)
                {
                    CommandType = CommandType.StoredProcedure
                };

                var title = new NpgsqlParameter()
                {
                    ParameterName = "@title",
                    Value         = award.Title
                };

                sqlCommand.Parameters.Add(title);

                var updatedRows = sqlCommand.ExecuteNonQuery();
            }
        }
Example #3
0
 public void UpdateAward(Award award)
 {
     try
     {
         using (var con = new SqlConnection(connectString))
         {
             SqlCommand command = con.CreateCommand();
             command.CommandType = CommandType.StoredProcedure;
             command.CommandText = "UpdateAward";
             command.Parameters.AddWithValue("Title", award.Title);
             command.Parameters.AddWithValue("Description", award.Description ?? "");
             command.Parameters.AddWithValue("ID", award.ID);
             con.Open();
             command.ExecuteNonQuery();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #4
0
        public int Add(Award award)
        {
            int          id     = 1;
            List <Award> awards = new List <Award>();

            if (File.Exists(ConfigurationManager.AppSettings["AwardsPath"]))
            {
                using (StreamReader sr = new StreamReader(ConfigurationManager.AppSettings["AwardsPath"], true))
                {
                    awards = JsonConvert.DeserializeObject <List <Award> >(sr.ReadToEnd());
                }

                if (awards.Any())
                {
                    id = awards[awards.Count - 1].Id + 1;
                }
                else
                {
                    id = 1;
                }

                awards.Add(new Award()
                {
                    Id = id, Title = award.Title
                });
            }
            else
            {
                awards.Add(new Award()
                {
                    Id = 1, Title = award.Title
                });
            }

            using (StreamWriter sw = new StreamWriter(ConfigurationManager.AppSettings["AwardsPath"], false))
            {
                sw.Write(JsonConvert.SerializeObject(awards));
            }
            return(id);
        }
Example #5
0
 public int AddAward(Award award)
 {
     try
     {
         object idAward;
         using (var con = new SqlConnection(connectString))
         {
             SqlCommand command = con.CreateCommand();
             command.CommandType = CommandType.StoredProcedure;
             command.CommandText = "AddAward";
             command.Parameters.AddWithValue("Title", award.Title);
             command.Parameters.AddWithValue("Description", award.Description ?? "");
             con.Open();
             idAward = command.ExecuteScalar();
         }
         return(Convert.ToInt32(idAward));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #6
0
        public IEnumerable <Award> GetAwardsList()
        {
            List <Award> awards = new List <Award>();

            using (var connection = new SqlConnection(DataBaseConfig.GetConnectionString()))
            {
                connection.Open();
                using (var command = new SqlCommand("GetAwards", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        var award = new Award(reader.GetInt32(0), reader.GetString(1), reader[2]?.ToString());
                        awards.Add(award);
                    }
                    reader.Close();
                }
                connection.Close();
            }
            return(awards);
        }
        public void Edit(Award awardForEdit)
        {
            using (SqlConnection connection = new SqlConnection(connectionString))
                using (SqlCommand command = connection.CreateCommand())
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "UpdateAward";

                    command.Parameters.Add(new SqlParameter("@awardId", SqlDbType.Int));
                    command.Parameters.Add(new SqlParameter("@newTitle", SqlDbType.NVarChar, 150));
                    command.Parameters.Add(new SqlParameter("@newDescription", SqlDbType.NVarChar, 150));

                    command.Prepare();

                    command.Parameters[0].Value = awardForEdit.Id;
                    command.Parameters[1].Value = awardForEdit.Title;
                    command.Parameters[2].Value = awardForEdit.Description;

                    connection.Open();

                    var result = command.ExecuteNonQuery();
                }
        }
Example #8
0
 public Award Add(Award award)
 {
     using (SqlConnection connection = new SqlConnection(_connectionString))
     {
         var command = connection.CreateCommand();
         command.CommandType = CommandType.StoredProcedure;
         command.CommandText = "dbo.AddAward";
         command.Parameters.AddWithValue("@title", award.Title);
         command.Parameters.AddWithValue("@image", award.Image == null ? (object)DBNull.Value : Convert.ToBase64String(award.Image));
         var idParameter = new SqlParameter()
         {
             DbType        = DbType.Int32,
             ParameterName = "@id",
             Value         = award.Id,
             Direction     = ParameterDirection.Output,
         };
         command.Parameters.Add(idParameter);
         connection.Open();
         command.ExecuteNonQuery();
         award.Id = (int)idParameter.Value;
         return(award);
     }
 }
Example #9
0
 private static void AddAwardByUser(ref List <Award> awardsByUser, List <Guid> awardGuids, Award award)
 {
     foreach (var guid in awardGuids)
     {
         if (award.Guid == guid)
         {
             awardsByUser.Add(award);
         }
     }
 }
Example #10
0
 public void Edit(Award awardForEdit)
 {
 }
 public void Save(Award award)
 {
     award.Id = _random.Next();
     _awards.Add(award);
 }
Example #12
0
 private void PrintLine(StreamWriter streamWriter, Award award)
 {
     streamWriter.Write(award.Guid.ToString() + Separator);
     streamWriter.Write(award.Title);
     streamWriter.WriteLine();
 }
Example #13
0
 public void Remove(Award award)
 {
     throw new NotImplementedException();
 }
Example #14
0
 public void Remove(Award award)
 {
     awards.Remove(award);
 }
 public void Delete(Award DeleteAward)
 {
     awardList.Remove(DeleteAward);
 }
Example #16
0
        public void Delete(int id)
        {
            Award awardForRemove = awardList.FirstOrDefault(u => u.Id == id);

            awardList.Remove(awardForRemove);
        }
 public void Delete(Award award)
 {
     _awards.Remove(award);
 }
 public void AddAward(long userId, Award award)
 {
     _users.Find(user => user.Id == userId).Awards.Add(award);
 }
Example #19
0
 public bool Update(int id, Award award)
 {
     throw new NotImplementedException();
 }
Example #20
0
 public void Delete(Award award)
 {
     Delete(award.Id);
 }
Example #21
0
 public Award Add(Award award)
 {
     award.Id = GetMaxId() + 1;
     File.AppendAllLines(_fileAwards, new[] { $"{award.Id}|{award.Title}" });//|{ Encoding.Default.GetString(award.Image)}" });
     return(award);
 }