public async Task <IHttpActionResult> PostdetalleTrans(detalleTrans detalleTrans) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.detalleTrans.Add(detalleTrans); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (detalleTransExists(detalleTrans.id)) { return(Conflict()); } else { throw; } } return(CreatedAtRoute("DefaultApi", new { id = detalleTrans.id }, detalleTrans)); }
public async Task <IHttpActionResult> PutdetalleTrans(int id, detalleTrans detalleTrans) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != detalleTrans.id) { return(BadRequest()); } db.Entry(detalleTrans).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!detalleTransExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetdetalleTrans(int id) { detalleTrans detalleTrans = await db.detalleTrans.FindAsync(id); if (detalleTrans == null) { return(NotFound()); } return(Ok(detalleTrans)); }
public async Task <IHttpActionResult> DeletedetalleTrans(int id) { detalleTrans detalleTrans = await db.detalleTrans.FindAsync(id); if (detalleTrans == null) { return(NotFound()); } db.detalleTrans.Remove(detalleTrans); await db.SaveChangesAsync(); return(Ok(detalleTrans)); }
public IHttpActionResult RealizarTransferencia(JObject jObject) { string nroCuenta1 = jObject.GetValue("nroCuenta1").ToString(); string nroCuenta2 = jObject.GetValue("nroCuenta2").ToString();; int monto = Convert.ToInt32(jObject.GetValue("monto").ToString());; string descripcion = jObject.GetValue("descripcion").ToString(); string oficina = jObject.GetValue("oficina").ToString(); string ubicacion = jObject.GetValue("ubicacion").ToString(); cuenta cuenta1 = db.cuenta.FirstOrDefault(c => c.nroCuenta == nroCuenta1); cuenta cuenta2 = db.cuenta.FirstOrDefault(c => c.nroCuenta == nroCuenta2); transaccion transaccion = new transaccion() { cuenta = cuenta1, cuenta1 = cuenta2 }; if (cuenta1.saldo >= monto) { cuenta1.saldo = cuenta1.saldo - monto; cuenta2.saldo = cuenta2.saldo + monto; db.Entry(cuenta1).State = EntityState.Modified; db.Entry(cuenta2).State = EntityState.Modified; transaccion.estado = "aceptado"; db.transaccion.Add(transaccion); detalleTrans detalleTrans = new detalleTrans() { monto = monto, idMoneda = 1, transaccion = transaccion }; db.detalleTrans.Add(detalleTrans); movimiento movimiento = new movimiento() { cuenta = cuenta1, descripcion = descripcion, fechaHora = DateTime.Now, monto = monto }; db.movimiento.Add(movimiento); detalleMov detalleMov = new detalleMov() { movimiento = movimiento, saldo = cuenta1.saldo - monto, oficina = oficina, ubicacion = ubicacion }; db.detalleMov.Add(detalleMov); movimiento movimiento2 = new movimiento() { cuenta = cuenta2, monto = monto, descripcion = descripcion, fechaHora = DateTime.Now }; db.movimiento.Add(movimiento2); detalleMov detalleMov2 = new detalleMov() { movimiento = movimiento2, saldo = cuenta2.saldo + monto, oficina = oficina, ubicacion = ubicacion }; db.detalleMov.Add(detalleMov2); } else { transaccion.estado = "cancelado"; db.transaccion.Add(transaccion); db.SaveChanges(); return(Content(HttpStatusCode.Conflict, "No hay suficientes fondos en la cuenta 1")); } try { db.SaveChanges(); } catch (Exception e) { return(Conflict()); } return(Ok()); }