示例#1
0
        public async Task UpdatePaymentMethod(string id, string paymentMethodSysId)
        {
            try
            {
                var bill = await _ravenDatabaseProvider.GetEntity <Bill>(id);

                if (bill == null)
                {
                    throw new Exception("Não foi encontrado nenhum lançamento financeiro com o id " + id);
                }

                var paymentMethod = SystemConstants.ListPaymentMethods().FirstOrDefault(x => x.SysId == paymentMethodSysId);
                if (paymentMethod == null)
                {
                    throw new ArgumentException("Não foi incontrado um meio de pagamento válido!");
                }


                bill.UpdatePaymentMethod(paymentMethod);

                if (!string.IsNullOrEmpty(bill.ServiceOrderId))
                {
                    var serviceOrder = await _ravenDatabaseProvider.GetEntity <ServiceOrder>(bill.ServiceOrderId);

                    serviceOrder.Bill.UpdatePaymentMethod(paymentMethod);
                    await _ravenDatabaseProvider.UpdateEntity <ServiceOrder>(serviceOrder.Id, serviceOrder);
                }

                await _ravenDatabaseProvider.UpdateEntity <Bill>(id, bill);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        public async Task NewBill(InputBillDto inputBillDto, string destiny)
        {
            try
            {
                var paymentMethod = SystemConstants.ListPaymentMethods().FirstOrDefault(wh => wh.SysId == inputBillDto.PaymentMethodSysId);
                var billDestiny   = destiny.ToUpper() == SystemConstants.BillDestinyReceive
                    ? SystemConstants.BillDestinyReceive
                    : SystemConstants.BillDestinyPay;

                var bill = new Bill(
                    paymentMethod,
                    inputBillDto.Value,
                    billDestiny,
                    SystemConstants.BillStatus_EmAberto,
                    inputBillDto.DueDate,
                    inputBillDto.Description
                    );

                await _ravenDatabaseProvider.CreateEntity <Bill>(bill);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#3
0
        public async Task NewServiceOrder(InputServiceOrderDto serviceOrderDto)
        {
            try
            {
                var session = await _ravenDatabaseProvider.GetSession();

                var paymentMethod = SystemConstants.ListPaymentMethods().FirstOrDefault(wh => wh.SysId == serviceOrderDto.PaymentMethodSysId);

                if (paymentMethod == null)
                {
                    throw new InvalidEnumArgumentException("Não foi encontrado um meio de pagamento válido");
                }

                var customer = await _ravenDatabaseProvider.GetEntity <Customer>(serviceOrderDto.CustomerId);

                if (customer == null)
                {
                    throw new InvalidEnumArgumentException("Não foi encontrado um cliente com o ID informado");
                }

                var bill = new Bill(
                    paymentMethod,
                    serviceOrderDto.Value,
                    SystemConstants.BillDestinyReceive,
                    SystemConstants.BillStatus_EmAberto,
                    serviceOrderDto.DueDate,
                    serviceOrderDto.Description
                    );

                await session.StoreAsync(bill);

                ServiceOrder serviceOrder = new ServiceOrder(DateTime.Now, serviceOrderDto.Description, customer, bill);

                await session.StoreAsync(serviceOrder);

                //await _ravenDatabaseProvider.CommitAsync(session);
                await session.SaveChangesAsync();

                session.Dispose();
                bill.SetServiceOrderId(serviceOrder.Id);
                await _ravenDatabaseProvider.UpdateEntity <Bill>(bill.Id, bill);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }