public static bool Modificar(Renta renta) { bool paso = false; Contexto contexto = new Contexto(); try { var rent = RentaBLL.Buscar(renta.RentaId); if (rent != null) { foreach (var item in renta.Detalles) { contexto.videoJuego.Find(item.VideoJuegoId).CantidadEjemplares = contexto.videoJuego.Find(item.VideoJuegoId).CantidadEjemplares + 1; if (!renta.Detalles.ToList().Exists(v => v.RentaId == item.RentaId)) { item.VideoJuego = null; contexto.Entry(item).State = EntityState.Deleted; } } foreach (var item in renta.Detalles) { contexto.videoJuego.Find(item.VideoJuegoId).CantidadEjemplares = contexto.videoJuego.Find(item.VideoJuegoId).CantidadEjemplares - 1; var estado = item.RentaId > 0 ? EntityState.Modified : EntityState.Added; contexto.Entry(item).State = estado; } } if (contexto.SaveChanges() > 0) { paso = true; } contexto.Dispose(); } catch (Exception) { throw; } return(paso); }
public async Task <IActionResult> Edit(int id, [Bind("Id,NoRenta,FechaRenta,FechaDevolucion,MontoXDia,CantidadDia,Comentario,Estado,EmpleadoId,VehiculoId,ClienteId")] Renta renta) { if (id != renta.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(renta); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RentaExists(renta.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ClienteId"] = new SelectList(_context.Clientes, "Id", "Id", renta.ClienteId); ViewData["EmpleadoId"] = new SelectList(_context.Empleados, "Id", "Id", renta.EmpleadoId); ViewData["VehiculoId"] = new SelectList(_context.Vehiculos, "Id", "Id", renta.VehiculoId); return(View(renta)); }
public static bool Modificar(Renta renta) { bool paso = false; Contexto db = new Contexto(); try { var Anterior = db.Renta.Find(renta.RentaId); db.Entry(renta).State = EntityState.Modified; foreach (var item in Anterior.Detalle) { /*if (!renta.Vehiculos.Exists(d => d.VehiculoID== item.VehiculoID)) * db.Entry(item).State = EntityState.Deleted;*/ if (item.VehiculoId == 0) { guardarDetalle(item); } else { db.Entry(item).State = EntityState.Modified; paso = db.SaveChanges() > 0; } } paso = (db.SaveChanges() > 0); } catch (Exception) { throw; } finally { db.Dispose(); } return(paso); }
public void InsertRenta(Renta rt) { if (rt.Id == 0) { var cliente = _db.Clientes.FirstOrDefault(x => x.Id == rt.Id_Cliente); cliente.LimiteCredito -= rt.MontoDiario * rt.Dias; rt.Cliente = cliente; _db.Rentas.Add(rt); } else { var rent = _db.Rentas.FirstOrDefault(x => x.Id == rt.Id); var cliente = _db.Clientes.FirstOrDefault(x => x.Id == rt.Id_Cliente); cliente.LimiteCredito -= rt.MontoDiario * rt.Dias; rt.Cliente = cliente; rent.FechaRenta = rt.FechaRenta; rent.Id_Cliente = rt.Id_Cliente; rent.Id_Empleado = rt.Id_Empleado; rent.Id_User = rt.Id_User; rent.Id_Vehiculo = rt.Id_Vehiculo; rent.Id_Estado = rt.Id_Estado; rent.FechaDevolucion = rt.FechaDevolucion; rent.MontoDiario = rt.MontoDiario; rent.FechaRenta = rt.FechaRenta; rent.Comentario = rt.Comentario; rent.Dias = rt.Dias; } _db.SaveChanges(); }
public async Task <IHttpActionResult> PutRenta(int id, Renta renta) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != renta.RentaID) { return(BadRequest()); } db.Entry(renta).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RentaExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public static bool Eliminar(int id) { bool paso = false; Contexto contexto = new Contexto(); try { Renta renta = contexto.renta.Find(id); if (renta != null) { foreach (var item in renta.Detalles) { contexto.videoJuego.Find(item.VideoJuegoId).CantidadEjemplares = contexto.videoJuego.Find(item.VideoJuegoId).CantidadEjemplares + 1; } renta.Detalles.Count(); contexto.renta.Remove(renta); } if (contexto.SaveChanges() > 0) { paso = true; } contexto.Dispose(); } catch (Exception) { throw; } return(paso); }
private void WriteRenta(Renta renta, string qrDecoded) { var code = renta.Sku.Nomenklatura.Code; var pt = ProductTypeEnum.Spirit.ToString(); if (renta.Sku.Nomenklatura.Specialisation.ProductType.Alias == pt) { var magic = new MagicService(); var intqr = int.Parse(qrDecoded); magic.PutSpiritInJar(intqr, code).GetAwaiter().GetResult(); qrDecoded = $"spirit {qrDecoded}"; } else { var name = renta.Sku.Name; var description = renta.Sku.Nomenklatura.Description; _ereminService.WriteQR(qrDecoded, code, name, description, renta.Count, renta.BasePrice, BillingHelper.GetFinalPrice(renta), renta.Secret, renta.Id, (Lifestyles)renta.LifeStyle).GetAwaiter().GetResult(); var oldQR = Get <Renta>(r => r.QRRecorded == qrDecoded); if (oldQR != null) { oldQR.QRRecorded = $"{qrDecoded} deleted"; } } renta.QRRecorded = qrDecoded; }
private Renta LlenaClase() { Renta renta = new Renta { Pago = PagonumericUpDown.Value, Devuelta = DevueltanumericUpDown.Value, FechaRegistro = FechadateTimePicker.Value, FechaDevuelta = DevueltadateTimePicker.Value, MiembroId = Convert.ToInt32(MiembrocomboBox.SelectedValue), RentaId = Convert.ToInt32(RentanumericUpDown.Value), Importe = ImportenumericUpDown.Value, Detalles = this.Detalle }; /*foreach (DataGridViewRow item in DetalledataGridView.Rows) * { * * Detalle.Add * (Convert.ToInt32(item.Cells["DetalleId"].Value), * renta.RentaId, * Convert.ToInt32(item.Cells["VideoJuegoId"].Value), * Convert.ToString(item.Cells["Titulo"].Value), * Convert.ToString(item.Cells["descripcion"].Value), * ToInt(item.Cells["cantidad"].Value), * ToDecimal(item.Cells["monto"].Value) * ); * * * }*/ return(renta); }
public void LlenarCampos(Renta renta) { DevueltadateTimePicker.Value = renta.FechaDevuelta; FechadateTimePicker.Value = renta.FechaRegistro; DevueltanumericUpDown.Value = renta.Devuelta; PagonumericUpDown.Value = renta.Pago; ImportenumericUpDown.Value = renta.Importe; }
public ActionResult DeleteConfirmed(int id) { Renta renta = db.Rentas.Find(id); db.Rentas.Remove(renta); db.SaveChanges(); return(RedirectToAction("Index")); }
public void DeleteRentaTest() { List <Renta> rentas = rDAL.ListRenta("Activo"); Renta renta = rentas.OrderByDescending(rr => rr.RentaID).FirstOrDefault(); int r = rDAL.DeleteRenta(renta.RentaID); Assert.IsTrue(r > 0); }
public int DeleteRenta(int id) { int r = 0; Renta renta = db.Renta.Find(id); renta.EstadoID = 2; r = ModificarRenta(renta); return(r); }
private void EditarButton_Click(object sender, RoutedEventArgs e) { Renta renta = (sender as Button).DataContext as Renta; RegistroRenta registroRenta = new RegistroRenta(renta.RentaId); registroRenta.Owner = this; registroRenta.Show(); }
private void ClienteIdButton_Click(object sender, RoutedEventArgs e) { Renta renta = (sender as Button).DataContext as Renta; RegistroCliente registroCliente = new RegistroCliente(renta.ClienteId); registroCliente.Owner = this; registroCliente.Show(); }
private void VehiculoIdButton_Click(object sender, RoutedEventArgs e) { Renta renta = (sender as Button).DataContext as Renta; RegistroVehiculo registroVehiculo = new RegistroVehiculo(renta.VehiculoId); registroVehiculo.Owner = this; registroVehiculo.Show(); }
public async Task <Renta> Actualizar(Renta renta, string token) { HttpClient client = GetClient(token); var response = await client.PutAsync(URL, new StringContent(JsonConvert.SerializeObject(renta), Encoding.UTF8, "application/json")); return(JsonConvert.DeserializeObject <Renta>(await response.Content.ReadAsStringAsync())); }
// GET: api/Renta/5 public Renta Get(int id) { Renta rent = renta.findRenta(id); if (renta == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NoContent)); } return(renta.findRenta(id)); }
private Renta LlenaClase() { Renta renta = new Renta(); renta.RentaId = Convert.ToInt32(RentaIDnumericUpDown.Value); renta.FechaRegistro = DateTime.Now; renta.FechaDevuelta = DateTime.Now; renta.Detalle = this.Detalle; return(renta); }
public int agregarrenta(Renta renta) { int r = 0; if (renta != null) { db.Renta.Add(renta); r = db.SaveChanges(); } return(r); }
public int ModificarRenta(Renta renta) { int r = 0; if (renta != null) { db.Entry(renta).State = EntityState.Modified; r = db.SaveChanges(); } return(r); }
public void CleanRenta(Renta renta) { if (!string.IsNullOrEmpty(renta.QRRecorded)) { var ereminService = new EreminService(); ereminService.CleanQR(renta.QRRecorded).GetAwaiter().GetResult(); renta.QRRecorded = $"deleted {renta.QRRecorded}"; } renta.Expired = true; SaveContext(); }
public async Task <IHttpActionResult> GetRenta(int id) { Renta renta = await db.Renta.FindAsync(id); if (renta == null) { return(NotFound()); } return(Ok(renta)); }
public IHttpActionResult GetAll() { List <Renta> reservas = new List <Renta>(); try { using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager .ConnectionStrings["Reservas"].ConnectionString)) { SqlCommand sqlCommand = new SqlCommand( @"SELECT REN_CODIGO , USU_IDENTIFICACION , AUTO_CODIGO , EMP_CODIGO , REN_DESCRIPCION , REN_CANTIDAD , REN_PRECIO , REN_FEC_RETIRO , REN_FEC_RETORNO FROM RENTA;", sqlConnection); sqlConnection.Open(); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); while (sqlDataReader.Read()) { Renta renta = new Renta() { REN_CODIGO = sqlDataReader.GetInt32(0), USU_IDENTIFICACION = sqlDataReader.GetString(1), AUTO_CODIGO = sqlDataReader.GetInt32(2), EMP_CODIGO = sqlDataReader.GetInt32(3), REN_DESCRIPCION = sqlDataReader.GetString(4), REN_CANTIDAD = sqlDataReader.GetInt32(5), REN_PRECIO = sqlDataReader.GetDecimal(6), REN_FEC_RETIRO = sqlDataReader.GetDateTime(7), REN_FEC_RETORNO = sqlDataReader.GetDateTime(8), }; reservas.Add(renta); } sqlConnection.Close(); } } catch (Exception e) { return(InternalServerError(e)); } return(Ok(reservas)); }
public void findrentaTest() { rDAL.agregarrenta(new Renta { UsuarioID = 1, ReservaID = 2, EstadoID = 1 }); List <Renta> rentas = rDAL.ListRenta("Activo"); Renta renta = rentas.OrderByDescending(rr => rr.RentaID).FirstOrDefault(); Renta re = rDAL.findrenta(renta.RentaID); Assert.IsTrue(renta.UsuarioID == re.UsuarioID && renta.ReservaID == re.ReservaID && renta.EstadoID == re.EstadoID); }
public ActionResult Edit([Bind(Include = "IdRenta,FechaRenta,FechaDebeDevolver,FechaDevolucion,IdCliente,IdCopiaPelicula")] Renta renta) { if (ModelState.IsValid) { db.Entry(renta).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdCliente = new SelectList(db.Cliente, "IdCliente", "Nombre", renta.IdCliente); ViewBag.IdCopiaPelicula = new SelectList(db.CopiaPelicula, "IdCopiaPelicula", "NombreOriginal", renta.IdCopiaPelicula); return(View(renta)); }
private void Limpiar() { RentaIdTextBox.Text = ""; FechaTextBox.Text = Convert.ToString(DateTime.Now); MiembroDropDownList.Text = string.Empty; DevueltaTextBox.Text = Convert.ToString(DateTime.Today); ImporteTextBox.Text = ""; PagoTextBox.Text = "0"; ViewState["Renta"] = new Renta(); DetalleGridView = null; this.BindGrid(); }
public void LlenarCampos(Renta renta) { RentaIdTextBox.Text = Convert.ToString(renta.RentaId); PagoTextBox.Text = Convert.ToString(renta.Pago); DevueltaTextBox.Text = Convert.ToString(renta.Devuelta); FechaTextBox.Text = Convert.ToString(renta.FechaRegistro); FechaDevueltaTextBox.Text = Convert.ToString(renta.FechaDevuelta); ImporteTextBox.Text = Convert.ToString(renta.Importe); MiembroDropDownList.Text = Convert.ToString(renta.MiembroId); this.BindGrid(); }
public async Task <IHttpActionResult> PostRenta(Renta renta) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Renta.Add(renta); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = renta.RentaID }, renta)); }
public ActionResult Edit([Bind(Include = "IdRenta,IdCarro,IdCliente,Duracion,Fecha")] Renta renta) { if (ModelState.IsValid) { db.Entry(renta).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.IdCarro = new SelectList(db.Carros, "IdCarro", "Nombre", renta.IdCarro); ViewBag.IdCliente = new SelectList(db.Clientes, "IdCliente", "Nombre", renta.IdCliente); return(View(renta)); }
public void ModificarRentaTest() { rDAL.agregarrenta(new Renta { UsuarioID = 1, ReservaID = 2, EstadoID = 1 }); List <Renta> rentas = rDAL.ListRenta("Activo"); Renta renta = rentas.OrderByDescending(rr => rr.RentaID).FirstOrDefault(); renta.ReservaID = 3; int r = rDAL.ModificarRenta(renta); Assert.IsTrue(r > 0); }