Ejemplo n.º 1
0
        public string CloseSubscription(string id, double amount)
        {
            try
            {
                ChitSubscriber chitSubscriber = FindBySubscriptionId(id);
                Voucher        voucher        = new Voucher
                {
                    VoucherDate = new DateTime(),
                };

                var bookId = bookService.FindByName(ChitDueService.VOUCHER_TYPE_NAME).Id;

                VoucherInfo[] voucherInfos = new VoucherInfo[2];
                voucherInfos[0] = new VoucherInfo()
                {
                    bookId    = bookId,
                    IsCredit  = false,
                    VoucherId = voucher.Id,
                    Amount    = amount,
                };
                voucherInfos[1] = new VoucherInfo()
                {
                    bookId    = bookId,
                    IsCredit  = true,
                    VoucherId = voucher.Id,
                    Amount    = amount
                };
                voucher.VoucherTypeId = _voucherTypeService
                                        .FindByName(VoucherTypeMasterEnum.Sales.ToString()).Id;
                voucher.VoucherTypeMaster      = null;
                chitSubscriber.ClosedVoucherId = voucher.Id;
                Repository.Update(chitSubscriber);
                UnitOfWork.GetRepository <VoucherInfo>().Add(voucherInfos);
                UnitOfWork.GetRepository <Voucher>().Add(voucher);

                UnitOfWork.SaveChanges();
            }
            catch (Exception exception)
            {
                return(exception.Message);
            }
            return(null);
        }
Ejemplo n.º 2
0
        public ChitSubriberDue Save(ChitSubscribeDomain domain)
        {
            ChitSubscriber  chitSubscriber  = null;
            ChitSubriberDue chitSubriberDue = new ChitSubriberDue()
            {
                DueNo   = GenerateDueId(),
                Voucher = new Voucher()
                {
                    VoucherDate   = DateTime.Now,
                    VoucherTypeId = voucherService.FindByName(VOUCHER_TYPE_NAME).Id,
                }
            };

            if (domain.SubscribeId == Guid.Empty)
            {
                Guid customerId = Guid.Empty;
                if (domain.CustomerId == Guid.Empty)
                {
                    var customer = new Customer()
                    {
                        Contact = new Contact()
                        {
                            FirstName    = domain.CustomerName,
                            Address      = domain.Address,
                            MobileNumber = domain.MobileNumber
                        }
                    };
                    UnitOfWork.GetRepository <Customer>().Add(customer);
                    customerId = customer.Id;
                }
                else
                {
                    customerId = domain.CustomerId;
                }
                chitSubscriber = new ChitSubscriber()
                {
                    ChitSchemeId = domain.ChitSchemeId,
                    CustomerId   = customerId,
                    JoinedDate   = DateTime.Now,
                    SubscribeId  = GenerateSubscribeId()
                };


                chitSubriberDue.ChitSubscriber = chitSubscriber;
            }
            else
            {
                chitSubriberDue.ChitSubscriberId = domain.SubscribeId;
            }

            VoucherInfo[] voucherInfos = new VoucherInfo[2];
            voucherInfos[0] = new VoucherInfo()
            {
                bookId    = bookService.FindByName(VOUCHER_TYPE_NAME).Id,
                IsCredit  = true,
                VoucherId = chitSubriberDue.Voucher.Id,
                Amount    = domain.Amount,
                FieldInfo = domain.FieldInfo
            };
            voucherInfos[1] = new VoucherInfo()
            {
                bookId    = bookService.FindByName(VOUCHER_TYPE_NAME).Id,
                IsCredit  = false,
                VoucherId = chitSubriberDue.Voucher.Id,
                Amount    = domain.Amount,
                FieldInfo = domain.FieldInfo
            };
            Repository.Add(chitSubriberDue);
            UnitOfWork.GetRepository <VoucherInfo>().Add(voucherInfos);
            UnitOfWork.SaveChanges();
            return(chitSubriberDue);
        }