Exemplo n.º 1
0
        public int Add(int idClient, int idAward)
        {
            if (GetAll() == null)
            {
                FakeDaoClientAward = new Dictionary <int, ClientAward>();
            }

            using (StreamWriter fileJson = new StreamWriter(_path, false))
            {
                var award = new ClientAward
                {
                    IdClient      = idClient,
                    IdAchievement = idAward
                };

                if (FakeDaoClientAward.Any())
                {
                    award.Id = FakeDaoClientAward.Select(x => x.Key).Max();
                    _id      = ++award.Id;
                }

                FakeDaoClientAward.Add(_id, award);

                var json = JsonConvert.SerializeObject(FakeDaoClientAward);
                fileJson.WriteLine(json);

                return(_id++);
            }
        }
Exemplo n.º 2
0
        public ClientAward Update(ClientAward clientAward)
        {
            if (GetAll() == null)
            {
                return(null);
            }

            var item = GetById(clientAward.Id);

            using (StreamWriter fileJson = new StreamWriter(_path, false))
            {
                if (!FakeDaoClientAward.Any())
                {
                    return(null);
                }

                if (item == null)
                {
                    return(null);
                }

                FakeDaoClientAward[clientAward.Id] = clientAward;

                var json = JsonConvert.SerializeObject(FakeDaoClientAward);
                fileJson.WriteLine(json);

                return(item);
            }
        }
Exemplo n.º 3
0
        public ClientAward Update(ClientAward clientAward)
        {
            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                var command = connection.CreateCommand();

                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "[dbo].[Sp_UpdateClientAward]";

                SqlParameter ParameterId = new SqlParameter
                {
                    DbType        = DbType.Int32,
                    ParameterName = "@Id",
                    Value         = clientAward.Id,
                    Direction     = ParameterDirection.Input
                };
                command.Parameters.Add(ParameterId);

                SqlParameter ParameterIdClient = new SqlParameter
                {
                    DbType        = DbType.Int32,
                    ParameterName = "@IdClient",
                    Value         = clientAward.IdClient,
                    Direction     = ParameterDirection.Input
                };
                command.Parameters.Add(ParameterIdClient);

                SqlParameter ParameterIdAward = new SqlParameter
                {
                    DbType        = DbType.Int32,
                    ParameterName = "@IdAward",
                    Value         = clientAward.IdAchievement,
                    Direction     = ParameterDirection.Input
                };
                command.Parameters.Add(ParameterIdAward);

                connection.Open();

                command.ExecuteNonQuery();

                //Бред какой то
                return(clientAward);
            }
        }
Exemplo n.º 4
0
 public ClientAward Update(ClientAward clientAward)
 {
     return(_clientAwardDao.Update(clientAward));
 }