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 CashFoundDto(CashFound cashFound) { Id = cashFound.Id; RegisterDate = cashFound.RegisterDate; Quantity = cashFound.Quantity; User = new UserDto(cashFound.User); CashRegister = new CashRegisterDto(cashFound.CashRegister); }
public CashRegisterDto AddCashRegister(CashRegisterDto cashRegisterDto, out string message) { try { using (PosRiContext dbContext = new PosRiContext()) { message = string.Empty; CashRegister cashRegister = new CashRegister { Name = cashRegisterDto.Name, IsActive = true }; CashFound cashFound = new CashFound { CashRegister = cashRegister, Quantity = 0, RegisterDate = DateTime.Now, //UserId = cashRegisterDto.User.Id }; dbContext.Entry(cashRegister).State = EntityState.Added; dbContext.Entry(cashFound).State = EntityState.Added; dbContext.CashRegisters.Add(cashRegister); dbContext.CashFounds.Add(cashFound); if (dbContext.SaveChanges() > 0) { cashRegisterDto.Id = cashRegister.Id; return(cashRegisterDto); } message = "No se pudo agregar la caja."; return(null); } } catch (Exception e) { message = $"No se pudo agregar la caja. {e.Message}"; return(null); } }