public List <Models.Time> ObterTimes()

        {
            Connection();

            List <Models.Time> tList = new List <Models.Time>();



            using (SqlCommand command = new SqlCommand("ObterTimes", sqlConn))
            {
                command.CommandType = System.Data.CommandType.StoredProcedure;

                sqlConn.Open();

                SqlDataReader rd = command.ExecuteReader();

                while (rd.Read())

                {
                    Models.Time time = new Models.Time()
                    {
                        id     = Convert.ToInt32(rd["TimeId"]),
                        nome   = Convert.ToString(rd["Time"]),
                        estado = Convert.ToString(rd["Estado"]),
                        cores  = Convert.ToString(rd["Cores"])
                    };

                    tList.Add(time);
                }
                sqlConn.Close();

                return(tList);
            }
        }
        public bool AdicionarTime(Models.Time time)
        {
            Connection();

            int i;

            using (SqlCommand command = new SqlCommand("InserirTime", sqlConn))
            {
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@Time", time.nome);
                command.Parameters.AddWithValue("@Estado", time.estado);
                command.Parameters.AddWithValue("@Cores", time.cores);

                sqlConn.Open();

                try
                {
                    i = command.ExecuteNonQuery();

                    if (i >= 1)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    string err = e.Message;
                    return(false);
                }
            }
        }
示例#3
0
        public ActionResult EditarTime(int id, Models.Time time)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _repTime = new Rep.TimeRepositorio();
                    _repTime.AtualizarTime(time);

                    return(RedirectToAction("ObterTodos"));
                }
                catch (Exception)
                {
                    return(View());
                }
            }
            return(View());
        }
示例#4
0
        public ActionResult IncluirTime(Models.Time time)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _repTime = new Rep.TimeRepositorio();

                    if (_repTime.AdicionarTime(time))
                    {
                        ViewBag.Mensagem = "Time Cadastrado com sucesso!";
                    }
                    return(RedirectToAction("ObterTodos"));
                }
                return(View());
            }
            catch (Exception)
            {
                return(View("ObterTodos"));
            }
        }
        public bool AtualizarTime(Models.Time time)
        {
            Connection();

            int i;

            using (SqlCommand command = new SqlCommand("AtualizarTime", sqlConn))
            {
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@TimeId", time.id);
                command.Parameters.AddWithValue("@Time", time.nome);
                command.Parameters.AddWithValue("@Estado", time.estado);
                command.Parameters.AddWithValue("@Cores", time.cores);

                sqlConn.Open();

                i = command.ExecuteNonQuery();

                return(i >= 1);
            }
        }
        public Models.Time ObterPorId(int Id)

        {
            Connection();



            using (SqlCommand command = new SqlCommand("ObterPorId", sqlConn))
            {
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@timeId", Id);

                sqlConn.Open();

                try
                {
                    SqlDataReader rd = command.ExecuteReader();

                    Models.Time myTime = new Models.Time();
                    while (rd.Read())
                    {
                        myTime.id     = Convert.ToInt32(rd["TimeId"]);
                        myTime.nome   = Convert.ToString(rd["Time"]);
                        myTime.estado = Convert.ToString(rd["Estado"]);
                        myTime.cores  = Convert.ToString(rd["Cores"]);
                    }
                    sqlConn.Close();

                    return(myTime);
                } catch (Exception e)
                {
                    string err = e.Message;
                    return(null);
                }
            }
        }
示例#7
0
        public List <TimeDTO> addTime(VenueDTO v)
        {
            TimeDTO t = new TimeDTO();

            t = v.times.Last();



            using (var db = new GG.Models.GGModelContainer())
            {
                if (t.id == null)
                {
                    Models.Time TimeTbl = new Models.Time();

                    TimeDTO newTime = new TimeDTO();

                    TimeTbl = new Models.Time
                    {
                        Text = t.timeText
                    };

                    db.Times.Add(TimeTbl);

                    db.SaveChanges();

                    newTime    = t;
                    newTime.id = TimeTbl.Id;

                    var existingTime = (from x in db.Times where x.Id == newTime.id select x).FirstOrDefault();


                    var existingVenue = (from x in db.Venues where x.Id == v.id select x).FirstOrDefault();

                    existingVenue.Times.Add(existingTime);

                    db.SaveChanges();

                    var l = (from x in existingVenue.Times
                             .Select(b => new TimeDTO
                    {
                        id = b.Id,
                        timeText = b.Text
                    })

                             select x).ToList();


                    return(l);
                }
                else
                {
                    Venue VenueTbl = new Venue();

                    var existingTime = (from x in db.Times where x.Id == t.id select x).FirstOrDefault();


                    var existingVenue = (from x in db.Venues where x.Id == v.id select x).FirstOrDefault();



                    existingVenue.Times.Add(existingTime);


                    db.SaveChanges();

                    var l = (from x in existingVenue.Times
                             .Select(b => new TimeDTO
                    {
                        id = b.Id,
                        timeText = b.Text
                    })

                             select x).ToList();


                    return(l);
                }
            }
        }