public CashFoundDto GetCashFound(int cashRegisterId, out string message) { try { using (PosRiContext dbContext = new PosRiContext()) { message = string.Empty; var cashfound = dbContext.CashFounds.LastOrDefault(c => c.CashRegisterId == cashRegisterId); if (cashfound != null) { var cashFoundDto = new CashFoundDto(cashfound); return(cashFoundDto); } return(new CashFoundDto()); } } catch (Exception e) { Console.WriteLine(e); throw; } }
public CashFoundDto SaveCashFound(CashFoundDto cashFoundDto, out string message) { try { using (PosRiContext dbContext = new PosRiContext()) { message = string.Empty; CashFound cashFound = new CashFound { UserId = cashFoundDto.User.Id, CashRegisterId = cashFoundDto.CashRegister.Id, Quantity = cashFoundDto.Quantity, RegisterDate = DateTime.Now }; dbContext.Entry(cashFound).State = EntityState.Added; dbContext.CashFounds.Add(cashFound); if (dbContext.SaveChanges() > 0) { cashFoundDto.Id = cashFound.Id; return(cashFoundDto); } message = "No se pudo agregar el fondo de caja."; return(null); } } catch (Exception e) { message = $"No se pudo agregar el fondo de caja. {e.Message}"; return(null); } }
public IHttpActionResult SaveCashFound(CashFoundDto cashFound) { CashRegisterManager cashRegisterManager = new CashRegisterManager(); string message; var newCashFound = cashRegisterManager.SaveCashFound(cashFound, out message); if (newCashFound != null) { return(Ok(cashFound)); } return(BadRequest(message)); }