public IHttpActionResult Post([FromBody] Cliente cliente) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Clientes.Add(cliente); db.SaveChanges(); return(CreatedAtRoute("Default", new { id = cliente.IdCliente }, cliente)); }
public IHttpActionResult Post([FromBody] Banco banco) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Bancos.Add(banco); db.SaveChanges(); return(CreatedAtRoute("Default", new { id = banco.IdBanco }, banco)); }
public IHttpActionResult Post([FromBody] AcompanhaColeta acompanha) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Acompanhas.Add(acompanha); db.SaveChanges(); return(CreatedAtRoute("Default", new { id = acompanha.IdAcompanha }, acompanha)); }
public IHttpActionResult Post([FromBody] Orcamento orcamento) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Orcamentos.Add(orcamento); db.SaveChanges(); return(CreatedAtRoute("Default", new { id = orcamento.IdColeta }, orcamento)); }
public IHttpActionResult Post([FromBody] Coleta coleta) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Coletas.Add(coleta); db.SaveChanges(); return(CreatedAtRoute("Default", new { id = coleta.IdColeta }, coleta)); }
public IHttpActionResult Post([FromBody] CartaoCredito cartao) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Cartao.Add(cartao); db.SaveChanges(); return(CreatedAtRoute("Default", new { id = cartao.IdCartao }, cartao)); }
public IHttpActionResult Post([FromBody] Material material) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Materials.Add(material); db.SaveChanges(); return(CreatedAtRoute("Default", new { id = material.IdMaterial }, material)); }
public IHttpActionResult Post([FromBody] Veiculo veiculo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Veiculos.Add(veiculo); db.SaveChanges(); return(CreatedAtRoute("Default", new { id = veiculo.IdVeiculo }, veiculo)); }
public IHttpActionResult Put([FromBody] ContaBancaria contaBancaria) { var entity = db.ContaBancarias.FirstOrDefault(e => e.IdContaBancaria == contaBancaria.IdContaBancaria); if (entity != null) { entity.IdBanco = contaBancaria.IdBanco; entity.MAgencia = contaBancaria.MAgencia; entity.MDigAgencia = contaBancaria.MDigAgencia; entity.MConta = contaBancaria.MConta; entity.MDigConta = contaBancaria.MDigConta; entity.IdTipoConta = contaBancaria.IdTipoConta; entity.MUltimaAtualizacao = contaBancaria.MUltimaAtualizacao; entity.IdStatus = contaBancaria.IdStatus; entity.MDataCadastro = contaBancaria.MDataCadastro; entity.IdStatus = contaBancaria.IdStatus; entity.Ccpf = contaBancaria.Ccpf; db.SaveChanges(); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, entity))); } else { return(ResponseMessage(Request.CreateResponse <string>(HttpStatusCode.NotFound, "Teste não localizado para alteração."))); } }
private static void AddCategories(MTContext context) { context.AddRange( new Category { Name = "Salary", Icon = "<i class=\"fas fa-briefcase fa-2x\" style=\"color: blue\"></i>" }, new Category { Name = "Car", Icon = "<i class=\"fas fa-car fa-2x\" style=\"color: red\"></i>" }, new Category { Name = "Clothing", Icon = "<i class=\"fas fa-tshirt fa-2x\" style=\"color: green\"></i>" }, new Category { Name = "Food", Icon = "<i class=\"fas fa-hamburger fa-2x\" style=\"color: orange\"></i>" }, new Category { Name = "Leisure", Icon = "<i class=\"fas fa-cocktail fa-2x\" style=\"color: red\"></i>" }, new Category { Name = "Living", Icon = "<i class=\"fas fa-home fa-2x\" style=\"color: black\"></i>" }, new Category { Name = "Others", Icon = "<i class=\"fas fa-file fa-2x\" style=\"color: black\"></i>" } ); context.SaveChanges(); }
public HttpResponseMessage Delete(int id) { try { using (MTContext entities = new MTContext()) { var entity = entities.Veiculos.FirstOrDefault(e => e.IdVeiculo == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Veiculo com o ID = " + id.ToString() + " não encontrado para deletar.")); } else { entities.Veiculos.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public IHttpActionResult Post([FromBody] ColetaVisualiza visualizacao) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.ColetasVisualiza.Add(visualizacao); db.SaveChanges(); return(CreatedAtRoute("Default", new { id = visualizacao.IdVisualiza }, visualizacao)); }
public IHttpActionResult Post([FromBody] ContaBancaria conta) { using (MTContext entities = new MTContext()) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } entities.ContaBancarias.Add(conta); entities.SaveChanges(); return(CreatedAtRoute("Default", new { id = conta.IdContaBancaria }, conta)); } }
public IHttpActionResult Post([FromBody] Status status) { using (MTContext entities = new MTContext()) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } entities.Status.Add(status); entities.SaveChanges(); return(CreatedAtRoute("Default", new { id = status.IdStatus }, status)); } }
public IHttpActionResult Post([FromBody] Motorista motorista) { using (MTContext entities = new MTContext()) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } entities.Motoristas.Add(motorista); entities.SaveChanges(); return(CreatedAtRoute("Default", new { id = motorista.IdMotorista }, motorista)); } }
public IHttpActionResult Put([FromBody] Status status) { var entity = db.Status.FirstOrDefault(e => e.IdStatus == status.IdStatus); if (entity != null) { // entity.IdCliente = cliente.IdCliente; entity.IdStatus = status.IdStatus; entity.DescricaoStatus = status.DescricaoStatus; db.SaveChanges(); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, entity))); } else { return(ResponseMessage(Request.CreateResponse <string>(HttpStatusCode.NotFound, "Status não localizado para alteração."))); } }
public IHttpActionResult Put([FromBody] Login login) { var entity = db.Acesso.FirstOrDefault(e => e.IdLogin == login.IdLogin); if (entity != null) { // entity.IdLogin = login.IdLogin; entity.Ccpf = login.Ccpf; entity.IdCliente = login.IdCliente; entity.Email = login.Email; entity.Senha = login.Senha; entity.IdTipoUsuario = login.IdTipoUsuario; entity.IdStatus = login.IdStatus; db.SaveChanges(); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, entity))); } else { return(ResponseMessage(Request.CreateResponse <string>(HttpStatusCode.NotFound, "Teste não localizado para alteração."))); } }
public IHttpActionResult Put([FromBody] Motorista motorista) { var entity = db.Motoristas.FirstOrDefault(e => e.IdMotorista == motorista.IdMotorista); if (entity != null) { entity.IdCliente = motorista.IdCliente; entity.IdMotorista = motorista.IdMotorista; entity.MnumeroCnh = motorista.MnumeroCnh; entity.McategoriaCnh = motorista.McategoriaCnh; entity.MvalidadeCnh = motorista.MvalidadeCnh; entity.IdStatus = motorista.IdStatus; db.SaveChanges(); return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK, entity))); } else { return(ResponseMessage(Request.CreateResponse <string>(HttpStatusCode.NotFound, "Teste não localizado para alteração."))); } }
private static void AddTransactions(MTContext context) { foreach (var item in context.Categories.ToList()) { switch (item.Name) { case "Salary": context.Add(new Transaction { CategoryId = item.Id, Amount = 4000, Date = DateTime.Now, Description = "July", TransactionType = true }); context.SaveChanges(); break; case "Car": context.Add(new Transaction { CategoryId = item.Id, Amount = 300, Date = DateTime.Now, Description = "Repair", TransactionType = false }); context.SaveChanges(); break; case "Food": context.Add(new Transaction { CategoryId = item.Id, Amount = 120, Date = DateTime.Now, Description = "McDonalds", TransactionType = false }); context.SaveChanges(); break; case "Living": context.Add(new Transaction { CategoryId = item.Id, Amount = 1200, Date = DateTime.Now, Description = "Rent", TransactionType = false }); context.SaveChanges(); break; case "Others": context.Add(new Transaction { CategoryId = item.Id, Amount = 550, Date = DateTime.Now, Description = "Gift", TransactionType = false }); context.SaveChanges(); break; case "Clothing": context.Add(new Transaction { CategoryId = item.Id, Amount = 550, Date = DateTime.Now, Description = "New shoes", TransactionType = false }); context.SaveChanges(); break; case "Leisure": context.Add(new Transaction { CategoryId = item.Id, Amount = 220, Date = DateTime.Now, Description = "Lent Ahmet money", TransactionType = false }); context.SaveChanges(); break; default: break; } } ; //context.AddRange( //new Transaction { CategoryId = 9, Amount = 4000, Date = DateTime.Now, Description = "July", TransactionType = true }, //new Transaction { CategoryId = 10, Amount = 300, Date = DateTime.Now, Description = "Repair", TransactionType = false }, //new Transaction { CategoryId = 11, Amount = 550, Date = DateTime.Now, Description = "New shoes", TransactionType = false }, //new Transaction { CategoryId = 12, Amount = 120, Date = DateTime.Now, Description = "McDonalds", TransactionType = false }, //new Transaction { CategoryId = 13, Amount = 220, Date = DateTime.Now, Description = "Lent Ahmet money", TransactionType = false }, //new Transaction { CategoryId = 14, Amount = 1200, Date = DateTime.Now, Description = "Rent", TransactionType = false }, //new Transaction { CategoryId = 15, Amount = 550, Date = DateTime.Now, Description = "Gift", TransactionType = false } //); context.SaveChanges(); }
public void Save() { _context.SaveChanges(); }