Пример #1
0
        public bool AddAdward(Adward adward)
        {
            using (SqlConnection con = new SqlConnection(conStr))
            {
                SqlCommand cmd = con.CreateCommand();
                con.Open();
                cmd.CommandText = "dbo.AddAward";
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                var IdParam = new SqlParameter()
                {
                    DbType        = System.Data.DbType.Int32,
                    ParameterName = "@Id",
                    Value         = adward.Id,
                    Direction     = System.Data.ParameterDirection.Output,
                };
                var TitleParam = new SqlParameter()
                {
                    DbType        = System.Data.DbType.String,
                    ParameterName = "@Title",
                    Value         = adward.Title,
                };
                cmd.Parameters.Add(IdParam);
                cmd.Parameters.Add(TitleParam);

                cmd.ExecuteNonQuery();
            }
            return(true);
        }
Пример #2
0
        public Adward AddAdward(string Title)
        {
            Adward adward = new Adward {
                Id = _adwardDao.GetAll().Count() + 1, Title = Title
            };

            if (_adwardDao.AddAdward(adward))
            {
                return(adward);
            }
            throw new ArgumentException("Error on adward added");
        }
Пример #3
0
 public IEnumerable <Adward> GetAll()
 {
     using (SqlConnection con = new SqlConnection(conStr))
     {
         SqlCommand cmd = con.CreateCommand();
         con.Open();
         cmd.CommandText = "dbo.GetAllAward";
         cmd.CommandType = System.Data.CommandType.StoredProcedure;
         SqlDataReader sqlDataReader = cmd.ExecuteReader();
         User[]        users         = new User[] { };
         while (sqlDataReader.Read())
         {
             int    Id    = (int)sqlDataReader["Id"];
             string Title = (string)sqlDataReader["Title"];
             Adward award = new Adward {
                 Id = Id, Title = Title
             };
             yield return(award);
         }
     }
 }
Пример #4
0
 public bool AddAdward(Adward adward)
 {
     _adwards.Add(_adwards.Keys.Count + 1, adward);
     Save();
     return(true);
 }