Ejemplo n.º 1
0
        public ActionResult CadLance(LanceGridDTO lanceDTO)
        {
            var lance = new Lance
            {
                PessoaId  = lanceDTO.PessoaId,
                ProdutoId = lanceDTO.ProdutoId,
                Valor     = lanceDTO.Valor,
            };
            var lstLance = repository.GetAllByProdutoId(lance.ProdutoId);

            if (lstLance.Count > 0)
            {
                foreach (var l in lstLance)
                {
                    if (l.Valor >= lance.Valor)
                    {
                        ModelState.AddModelError("Valor", "Existe outro lance igual ou maior com valor de: R$" + l.Valor.ToString());
                        return(CadLance());
                    }
                }
            }

            if (ModelState.IsValid)
            {
                repository.Save(lance);
                return(RedirectToAction("IndexLance"));
            }
            else
            {
                return(View(lance));
            }
        }
Ejemplo n.º 2
0
        public List <LanceGridDTO> GetAll(string nomePessoa)
        {
            string sql = "Select a.Id, a.Valor, b.Nome as PessoaNome, c.Nome as ProdutoNome FROM Leilao.Lance a JOIN Leilao.Pessoa b ON a.PessoaId = b.Id JOIN Leilao.Produto c ON a.ProdutoId = c.Id";

            if (!nomePessoa.IsNullOrWhiteSpace())
            {
                sql += " WHERE b.Nome like '%" + nomePessoa + "%' ORDER BY b.Nome;";
            }
            else
            {
                sql += " ORDER BY b.Nome;";
            }

            using (var conn = new SqlConnection(StringConnection))
            {
                var cmd = new SqlCommand(sql, conn);
                List <LanceGridDTO> list = new List <LanceGridDTO>();
                LanceGridDTO        p    = null;
                try
                {
                    conn.Open();
                    using (var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        while (reader.Read())
                        {
                            p             = new LanceGridDTO();
                            p.Id          = (int)reader["Id"];
                            p.PessoaNome  = reader["PessoaNome"].ToString();
                            p.ProdutoNome = reader["ProdutoNome"].ToString();
                            p.Valor       = (decimal)reader["Valor"];
                            list.Add(p);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }
                return(list);
            }
        }