public long RetIdPortifolio() { bool state = false; string query = "Select Max(Id_Portifolio)as 'Id_Portifolio' from Portifolio p inner join Categoria c on p.Categoria = c.IdCategoria"; SqlDataReader dr; Portifolio p = new Portifolio(); int Id_Portifolio = 0; try { using (SqlConnection cn = Conexao.conectar()) { using (SqlCommand cmd = new SqlCommand(query, cn)) { dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows == false) { Id_Portifolio = 0; } else { Id_Portifolio = Convert.ToInt32(dr["Id_Portifolio"]); } } } } catch (Exception ex) { LogRepository log = new LogRepository(); log.InsertLog(ex.Message); } return(Id_Portifolio); }
public bool ValidatePortifolio(string name) { bool state = false; string query = "Select * from Portifolio where Titulo = @Titulo"; SqlDataReader dr; Portifolio p = new Portifolio(); try { using (SqlConnection cn = Conexao.conectar()) { using (SqlCommand cmd = new SqlCommand(query, cn)) { cmd.Parameters.AddWithValue("@Titulo", name.Trim()); dr = cmd.ExecuteReader(); if (dr.HasRows == false) { return(state = false); } else { return(state = true); } } } } catch (Exception ex) { LogRepository log = new LogRepository(); log.InsertLog(ex.Message); } return(state); }
public Portifolio Edit(Portifolio model) { string query = "Update Portifolio set Categoria=@Categoria,Titulo=@Titulo,Imagem=@Imagem,Link=@Link where Id_Portifolio=@Id_Portifolio "; try { using (SqlConnection cn = Conexao.conectar()) { using (SqlCommand cmd = new SqlCommand(query, cn)) { cmd.Parameters.AddWithValue("@Id_Portifolio", model.Id_Portifolio); cmd.Parameters.AddWithValue("@Categoria", model.categoria.IdCategoria); cmd.Parameters.AddWithValue("@Titulo", model.Titulo); cmd.Parameters.AddWithValue("@Imagem", model.Imagem); cmd.Parameters.AddWithValue("@Link", model.Link); cmd.ExecuteNonQuery(); } } } catch (Exception ex) { LogRepository log = new LogRepository(); log.InsertLog(ex.Message); } return(model); }
static void Main(string[] args) { ObsLib.IPortifolio a = new Portifolio("Hans"); IPortifolioDisplay b = new portifolioDisplay(); Stock stockGoo = new Stock("google", 100.00, 80); Stock stockapl = new Stock("Apple", 200.00, 90); PriceChanger newPricesGoo = new PriceChanger(); PriceChanger newPricesApp = new PriceChanger(); newPricesGoo.priceChanger(stockGoo); newPricesApp.priceChanger(stockapl); a.buyStock(10, stockGoo); a.buyStock(20, stockapl); b.print(a); // stockGoo.Price = 250; a.buyStock(20, stockGoo); b.print(a); Console.ReadLine(); }
public void Stock_Availibilety_test(int availible, int buyAmount, int afterBuyAmount) { Stock _uut2 = new Stock("test2", 102.0, availible); Portifolio port = new Portifolio("jasper"); port.buyStock(buyAmount, _uut2); NUnit.Framework.Assert.That(_uut2.AvailibleAmount, Is.EqualTo(afterBuyAmount)); }
public async Task <ActionResult <Portifolio> > Post([FromBody] Portifolio model) { var Model = db.Insert(model); if (Model == null) { return(BadRequest(new { Message = "Dados Invalidos Revise os dados e tente denovo" })); } return(Model); }
public void Stock_Attach_Notifi_test() { Stock _uut2 = new Stock("test2", 102.0, 50); Portifolio port = Substitute.For <Portifolio>("jasper"); //act _uut2.attach(port); _uut2.Price = 40; //assert port.Received(1).update("test2", 40); }
public IActionResult InsertPortifolio([FromBody] Portifolio portifolio) { try { portifolio.Fotos = portifolio.Fotos.Select(x => new FotoPortifolio(x.Foto, portifolio.IdPortifolio)).ToList(); Portifolio.Save(portifolio); return(new JsonResult("Portifólio Incluído!")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public IActionResult UpdatePortifolio([FromBody] Portifolio portifolio) { try { portifolio.Fotos.Where(x => x.IdPortifolio == 0).Select(x => x.IdPortifolio = portifolio.IdPortifolio); Portifolio.Save(portifolio); return(new JsonResult("Portifólio Editado!")); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <ActionResult <Portifolio> > Put(int id, [FromBody] Portifolio model) { var Model = db.GetPortifolioById(id); if (Model != null) { model.Id_Portifolio = id; return(db.Edit(model)); } else { return(NotFound(new { Message = "Dados Invalidos ou inexistentes Revise os dados e tente denovo" })); } }
public IEnumerable <Portifolio> GetAllPortifolio() { string query = "Select *from Portifolio p inner join Categoria c on p.Categoria = c.IdCategoria"; SqlDataReader dr; List <Portifolio> list = new List <Portifolio>(); Portifolio p = new Portifolio(); try { using (SqlConnection cn = Conexao.conectar()) { using (SqlCommand cmd = new SqlCommand(query, cn)) { dr = cmd.ExecuteReader(); while (dr.Read()) { if (dr.HasRows == null) { return(null); } else { list.Add( p = new Portifolio() { Id_Portifolio = Convert.ToInt32(dr["Id_Portifolio"]), Titulo = dr["Titulo"].ToString(), categoria = new Categoria { IdCategoria = Convert.ToInt32(dr["Categoria"]), Nome_Categoria = dr["Nome_Categoria"].ToString() }, Imagem = dr["Imagem"].ToString(), Link = dr["Link"].ToString() }); } } } } } catch (Exception ex) { LogRepository log = new LogRepository(); log.InsertLog(ex.Message); } return(list); }
public HttpResponseMessage Create(Portifolio portifolio) { var response = new HttpResponseMessage(); try { portifolio = _service.Portifolio.Create(portifolio); response = Request.CreateResponse(HttpStatusCode.OK, portifolio); } catch (Exception ex) { response = Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message); } return response; }
public Portifolio GetPortifolioById(int Id) { string query = " Select * from Portifolio p inner join Categoria c on p.Categoria = c.IdCategoria where Id_Portifolio =@Id_Portifolio "; SqlDataReader dr; Portifolio p = new Portifolio(); try { using (SqlConnection cn = Conexao.conectar()) { using (SqlCommand cmd = new SqlCommand(query, cn)) { cmd.Parameters.AddWithValue("@Id_Portifolio", Id); dr = cmd.ExecuteReader(); dr.Read(); if (dr.HasRows == false) { return(null); } else { p = new Portifolio { Id_Portifolio = Convert.ToInt32(dr["Id_Portifolio"]), Titulo = dr["Titulo"].ToString(), categoria = new Categoria { IdCategoria = Convert.ToInt32(dr["Categoria"]), Nome_Categoria = dr["Nome_Categoria"].ToString() }, Imagem = dr["Imagem"].ToString(), Link = dr["Link"].ToString() }; } } } } catch (Exception ex) { LogRepository log = new LogRepository(); log.InsertLog(ex.Message); } return(p); }
public static void ReadInput() { Console.WriteLine(); Console.WriteLine("Enter the reference date of the negotiation"); var date = Convert.ToDateTime(Console.ReadLine()); Console.WriteLine("Enter the number of trades"); var countTrade = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter trade data"); while (countTrade > _listTrades.Count) { string[] inputs = Console.ReadLine().Split(' '); _listTrades.Add(new Trade( Convert.ToDouble(inputs[0]), inputs[1].ToString(), Convert.ToDateTime(inputs[2]))); } Console.WriteLine(); if (_listTrades.Count > 0) { var port = new Portifolio(date, countTrade, _listTrades); Console.WriteLine(new CategoryService().AnalyzerTradeService(port)); } else { Console.WriteLine("No data found !"); } Console.ReadKey(); }
public Portifolio Insert(Portifolio model) { string query = "Insert into Portifolio(Categoria,Titulo,Imagem,Link) values(@Categoria,@Titulo,@Imagem,@Link)"; try { if (ValidatePortifolio(model.Titulo) == false) { using (SqlConnection cn = Conexao.conectar()) { using (SqlCommand cmd = new SqlCommand(query, cn)) { cmd.Parameters.AddWithValue("@Categoria", model.categoria.IdCategoria); cmd.Parameters.AddWithValue("@Titulo", model.Titulo); cmd.Parameters.AddWithValue("@Imagem", model.Imagem); cmd.Parameters.AddWithValue("@Link", model.Link); cmd.ExecuteNonQuery(); long Id = RetIdPortifolio(); if (Id != 0) { model.Id_Portifolio = (int)Id; } } } } else { return(model = null); } } catch (Exception ex) { LogRepository log = new LogRepository(); log.InsertLog(ex.Message); } return(model); }
public void Init() { _uut = new Portifolio("jasper"); stock = new Stock("goo", 100.80, 50); }
public string AnalyzerTradeService(Portifolio port) { return(string.Join("\n", port.ListTrade.Select(item => $"{ _categoryService.Find(i => i.VerifyRisk(port.DataReference, item)).GetCategory() }"))); }