Пример #1
0
        public List <Treater> GetList()
        {
            List <Treater> lit = new List <Treater>();

            //lit = Cand_GetList;
            using (SqlConnection connection = new SqlConnection("Server=(localdb)\\MSSQLLocalDB;Database=master;"))
            {
                using (SqlCommand command = new SqlCommand("Treaters_GetList", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Treater trea = new Treater();
                            trea.Name    = reader["Name"].ToString();
                            trea.FavCand = (int)reader["FavoriteCandyID"];
                            trea.Cost    = (int)reader["CostumeID"];
                            trea.ID      = (int)reader["ID"];

                            lit.Add(trea);
                        }
                    }
                }
            }
            return(lit);
        }
        public List <Treater> GetList()
        {
            List <Treater> treaterList = new List <Treater>();

            using (SqlConnection connection = new SqlConnection(GetConnectionString()))
            {
                using (SqlCommand command = new SqlCommand("Treaters_GetList", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Candy candy = new Candy();
                            candy.id          = (int)reader["CandyID"];
                            candy.productName = reader["CandyName"].ToString();
                            Costume costume = new Costume();
                            costume.id      = (int)reader["CostumeID"];
                            costume.costume = reader["CostumeName"].ToString();

                            Treater treater = new Treater();
                            treater.id            = (int)reader["TreaterID"];
                            treater.name          = reader["TreaterName"].ToString();
                            treater.favoriteCandy = candy;
                            treater.costume       = costume;
                            treaterList.Add(treater);
                        }
                    }
                }
            }
            return(treaterList);
        }
Пример #3
0
        public List <Treater> GetList()
        {
            List <Treater> treaterList = new List <Treater>();

            using (SqlConnection connection = new SqlConnection(GetConnectionString()))
            {
                using (SqlCommand command = new SqlCommand("Treaters_GetList", connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Treater treater = new Treater
                            {
                                Id              = (int)reader["Id"],
                                Name            = reader["Name"].ToString(),
                                FavoriteCandyID = (int)reader["FavoriteCandyID"],
                                CostumeID       = (int)reader["CostumeID"]
                            };
                            treaterList.Add(treater);
                        }
                    }
                }
            }
            return(treaterList);
        }
Пример #4
0
        public void Insert(Treater treater)
        {
            List <Treater> treaterList = GetList();

            treater.id = (treaterList.Count <= 0) ? 0 : treaterList.Select(m => m.id).Max() + 1;

            treaterList.Add(treater);
            WriteList(treaterList);
        }
Пример #5
0
        public void Insert(Treater treater)
        {
            _treaterList.Add(treater);

            using (StreamWriter sw = new StreamWriter(_treaterDir))
            {
                sw.Write(JsonConvert.SerializeObject(_treaterList));
            }
        }
        public static TreaterModel GetTreaterModel(this Treater treater)
        {
            TreaterModel model = new TreaterModel();

            model.TreaterID   = treater.id;
            model.TreaterName = treater.name;
            model.CandyID     = treater.favoriteCandy.id;
            model.CandyName   = treater.favoriteCandy.productName;
            model.CostumeID   = treater.costume.id;
            model.CostumeName = treater.costume.costume;

            return(model);
        }
Пример #7
0
 public void Insert(Treater treater)
 {
     using (SqlConnection connection = new SqlConnection(GetConnectionString()))
     {
         using (SqlCommand command = new SqlCommand("Treaters_Insert", connection))
         {
             command.CommandType = CommandType.StoredProcedure;
             connection.Open();
             command.Parameters.AddWithValue("@Name", treater.Name);
             command.Parameters.AddWithValue("@FavoriteCandyID", treater.FavoriteCandyID);
             command.Parameters.AddWithValue("@CostumeID", treater.CostumeID);
             command.ExecuteNonQuery();
         }
     }
 }
Пример #8
0
 public void Insert(Treater treat)
 {
     using (SqlConnection connection = new SqlConnection("Server=(localdb)\\MSSQLLocalDB;Database=master;"))
     {
         using (SqlCommand command = new SqlCommand("Treaters_Insert", connection))
         {
             command.CommandType = CommandType.StoredProcedure;
             connection.Open();
             command.Parameters.AddWithValue("@Name", treat.Name);
             command.Parameters.AddWithValue("@Candy", treat.FavCand);
             command.Parameters.AddWithValue("@Costume", treat.Cost);
             command.ExecuteNonQuery();
         }
     }
 }
        public static Treater GetTreaterObject(this TreaterModel model)
        {
            Treater treater = new Treater();

            treater.id                        = model.TreaterID;
            treater.name                      = model.TreaterName;
            treater.favoriteCandy             = new Candy();
            treater.favoriteCandy.id          = model.CandyID;
            treater.favoriteCandy.productName = model.CandyName;
            treater.costume                   = new Costume();
            treater.costume.id                = model.CostumeID;
            treater.costume.costume           = model.CostumeName;

            return(treater);
        }
Пример #10
0
        public IActionResult Index(TreaterM model)
        {
            if (!ModelState.IsValid)
            {
                model.CandyList   = _CandyRepo.GetList();
                model.CostumeList = _CostRepo.GetList();
                model.TreaterList = _TreatRepo.GetList();
                return(View(model));
            }
            Treater tre = new Treater();

            tre.Name    = model.Name;
            tre.Cost    = model.CostumeID;
            tre.FavCand = model.CandyID;
            _TreatRepo.Insert(tre);
            return(RedirectToAction("Index"));
        }
Пример #11
0
        public IActionResult Index(TreaterModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Treater treater = new Treater
            {
                Name            = model.Name,
                FavoriteCandyID = model.FavoriteCandyID,
                CostumeID       = model.CostumeID
            };

            _treaterRepo.Insert(treater);

            return(RedirectToAction("Index"));
        }
Пример #12
0
        public void Insert(Treater treater)
        {
            List <Treater> list = GetList();

            if (list.Count() != 0)
            {
                treater.ID = list.Max(C => C.ID) + 1;
            }
            else
            {
                treater.ID = 1;
            }
            list.Add(treater);
            using (StreamWriter sw = new StreamWriter(System.IO.Path.Combine(AppDomain.CurrentDomain.GetData("DataDirectory").ToString(), "Treaters.json")))
            {
                string filedata = JsonConvert.SerializeObject(list);
                sw.Write(filedata);
            }
        }