Ejemplo n.º 1
0
        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;
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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));
        }