public void Update(PdvHistory entity)
 {
     if (entity == null)
     {
         throw new ArgumentNullException("entity");
     }
     context.SaveChanges();
 }
        public void Insert(PdvHistory entity)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            entities.Add(entity);
            context.SaveChanges();
        }
        public void Delete(Guid id)
        {
            if (id == null)
            {
                throw new ArgumentNullException("entity");
            }

            PdvHistory entity = entities.SingleOrDefault(s => s.Id == id);

            entities.Remove(entity);
            context.SaveChanges();
        }
示例#4
0
        public Pdv PayBill(double payment, double total)
        {
            try
            {
                var _pdv = new Pdv();
                _pdv.InitiatePdv();
                _pdv.Compute(total, payment);

                // A gravação e tratativas do Histórico também poderia ser controlada
                // por um evento e um controlador deste evento
                // permitindo desacoplar mais a lógica deste código

                if (_pdv.IsClosed.HasValue && _pdv.IsClosed.Value)
                {
                    var historyIn = new PdvHistory
                    {
                        Amount        = payment,
                        CreatedAt     = DateTime.Now,
                        OperationType = OperationType.In
                    };
                    _unitOfWork.PdvHistoryRepository.Insert(historyIn);

                    if (_pdv.BankCoinsToReturn.Count > 0 || _pdv.BankNotesToReturn.Count > 0)
                    {
                        var historyOut = new PdvHistory
                        {
                            Amount        = _pdv.BankNotesToReturn.Sum(b => b) + _pdv.BankCoinsToReturn.Sum(b => b),
                            CreatedAt     = DateTime.Now,
                            OperationType = OperationType.Out
                        };
                        _unitOfWork.PdvHistoryRepository.Insert(historyOut);
                    }
                }

                return(_pdv);
            }
            catch (Exception)
            {
                throw;
            }
        }