Exemplo n.º 1
0
        public Bill InitializeBill(DeliveryOrderCreateModel deliveryOrderCreateDto, string initiatorName)
        {
            User addressee = _userRepository.FindByEmail(deliveryOrderCreateDto.AddresseeEmail);

            if (addressee == null)
            {
                throw new NoSuchUserException();
            }
            Way way = _wayRepository.FindByLocalitySand_IdAndLocalityGet_Id(deliveryOrderCreateDto.LocalitySandId
                                                                            , deliveryOrderCreateDto.LocalityGetId);

            if (way == null)
            {
                throw new NoSuchWayException();
            }
            Delivery newDelivery = getBuildDelivery(deliveryOrderCreateDto, addressee, way);

            _deliveryRepository.Create(newDelivery);
            User user = _userRepository.FindByName(initiatorName);

            if (user == null)
            {
                throw new NoSuchUserException();
            }
            Bill buildBill = getBuildBill(newDelivery
                                          , calculateDeliveryCost(deliveryOrderCreateDto.DeliveryWeight, way)
                                          , user);

            _billRepository.Create(
                buildBill);
            _billRepository.Save();
            return(buildBill);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create(BillForCreateDto billForCreateDto)
        {
            var billToCreate = new Bill
            {
                StaffId     = billForCreateDto.StaffId,
                MemberId    = billForCreateDto.MemberId,
                CreatedDate = billForCreateDto.CreatedDate,
                Value       = billForCreateDto.Value
            };

            var createdBill = await _repo.Create(billToCreate);

            var bills = _context.Bills.ToList();

            var id = bills[bills.Count - 1].Id;

            foreach (var detail in billForCreateDto.BillDetails)
            {
                var detailToCreate = new BillDetail
                {
                    BillId          = id,
                    ProductDetailId = detail.ProductDetailId,
                    Amount          = detail.Amount
                };

                var createBillDetail = await _repo.CreateBillDetail(detailToCreate);
            }

            return(StatusCode(201));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Checkout(CheckoutViewModel model)
        {
            var session = HttpContext.Session.Get <List <ShoppingCartViewModel> >(CommonConstants.CartSession);

            if (ModelState.IsValid)
            {
                if (session != null)
                {
                    var details = new List <BillDetailViewModel>();
                    foreach (var item in session)
                    {
                        details.Add(new BillDetailViewModel()
                        {
                            Product   = item.Product,
                            Price     = item.Price,
                            Quantity  = item.Quantity,
                            ProductId = item.Product.Id
                        });
                    }
                    var billViewModel = new BillViewModel()
                    {
                        CustomerMobile  = model.CustomerMobile,
                        BillStatus      = BillStatus.New,
                        CustomerAddress = model.CustomerAddress,
                        CustomerName    = model.CustomerName,
                        CustomerMessage = model.CustomerMessage,
                        BillDetails     = details
                    };
                    if (User.Identity.IsAuthenticated == true)
                    {
                        billViewModel.CustomerId = Guid.Parse(UserManager.GetUserId(User));
                    }
                    _billRepository.Create(billViewModel);
                    try
                    {
                        _billRepository.Save();

                        //var content = await _viewRenderService.RenderToStringAsync("Cart/_BillMail", billViewModel);
                        //Send mail
                        //await _emailSender.SendEmailAsync(_configuration["MailSettings:AdminMail"], "New bill from Panda Shop", content);
                        ViewData["Success"] = true;
                    }
                    catch (Exception ex)
                    {
                        ViewData["Success"] = false;
                        ModelState.AddModelError("", ex.Message);
                    }
                }
            }
            model.Carts = session;
            return(View(model));
        }
Exemplo n.º 4
0
        public async Task CreateSaleAsync(long customerId, Dictionary <int, int> products)
        {
            Sale sale = new Sale
            {
                CustomerId = customerId,
                Total      = products.Values.Sum()
            };
            int saleId = await _saleRepository.CreateAsync(sale);

            IEnumerable <Bill> bills = products.Select(x => new Bill
            {
                SaleId    = saleId,
                ProductId = x.Key,
                Quantity  = x.Value
            });

            _billRepository.Create(bills);
        }
Exemplo n.º 5
0
 public IActionResult SaveEntity(BillViewModel billVm)
 {
     if (!ModelState.IsValid)
     {
         IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
         return(new BadRequestObjectResult(allErrors));
     }
     if (billVm.Id == 0)
     {
         _billRepository.Create(billVm);
     }
     else
     {
         _billRepository.Update(billVm);
     }
     _productRepository.Save();
     _billRepository.Save();
     return(new OkObjectResult(billVm));
 }
Exemplo n.º 6
0
        public async Task <IActionResult> PostBill(BillForCreateDto bill)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var categoryFromRepo = _categoryRepository.GetCategoryByName(bill.CategoryName);

            if (categoryFromRepo == null)
            {
                return(BadRequest());
            }

            var billToAdd = Mapper.Map <Bill>(bill);

            billToAdd.BudgetCategory = categoryFromRepo;

            await _billRepository.Create(billToAdd);

            return(CreatedAtAction("GetBill", new { id = bill.Id }, bill));
        }
        public IActionResult CheckOut(Bill billVM)
        {
            var cart    = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart");
            var userTmp = _userProfileDatabase.Find(s => s.UserName == User.Identity.Name).FirstOrDefault();

            //Count Discount
            int discount = 0;

            if (userTmp.Score >= 10 && userTmp.Score < 30)
            {
                discount = 10;
            }
            else if (userTmp.Score >= 30 && userTmp.Score < 50)
            {
                discount = 20;
            }
            else if (userTmp.Score >= 50)
            {
                discount = 30;
            }

            //Create Bill
            var total      = cart.Sum(item => item.Product.Price * item.Quantity);
            var orderTotal = total - ((total * discount) / 100);

            billVM.UserId      = userTmp.UserID;
            billVM.CreatedDate = DateTime.Now;
            billVM.Discount    = discount;
            billVM.TotalPrice  = total;
            billVM.OrderTotal  = orderTotal;
            billVM.State       = 1;
            //Bill bill = new Bill
            //{
            //    UserId = userTmp.UserID,
            //    CreatedDate = DateTime.Now,
            //    Discount = discount,
            //    TotalPrice = total,
            //    OrderTotal = orderTotal,
            //    State = 1
            //};
            _billDatabase.Create(billVM);

            //Create BillProduct
            int billId = _database.Bills.Max(m => m.BillID);

            foreach (var item in cart)
            {
                BillProduct billPro = new BillProduct
                {
                    BillID    = billId,
                    ProductID = item.Product.ProductID,
                    Quantity  = item.Quantity,
                    Total     = item.Quantity * item.Product.Price
                };
                _billProductDatabase.Create(billPro);
            }

            //Remove Cart
            List <Item> removeCart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart");

            removeCart = null;
            SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", removeCart);

            //Sending Email
            //using (var message = new MailMessage())
            //{
            //    message.To.Add(new MailAddress("*****@*****.**", "To Name"));
            //    message.From = new MailAddress("*****@*****.**", "From Name");
            //    message.CC.Add(new MailAddress("*****@*****.**", "CC Name"));
            //    message.Bcc.Add(new MailAddress("*****@*****.**", "BCC Name"));
            //    message.Subject = "Subject";
            //    message.Body = "Body";
            //    message.IsBodyHtml = true;
            //}
            //using (var client = new SmtpClient("smtp.gmail.com"))
            //{
            //    client.Port = 587;
            //    client.Credentials = new NetworkCredential("*****@*****.**", "password");
            //    client.EnableSsl = true;
            //    client.Send(message);
            //}

            return(RedirectToAction("ProductView", "Product"));
        }
 public int Create(BillForm body)
 {
     return(_repository.Create(body.ToDal()));
 }
Exemplo n.º 9
0
        public async Task <IEnumerable <BillModel> > GenerateChargeBills()
        {
            var hasSetting = int.TryParse((await _settingRepository.Get(SystemSettings.BillPaymentPeriodLength)).Setting, out int paymentPeriodLength);

            if (!hasSetting)
            {
                throw new LogicException("Bill payment period length not defined.");
            }

            var billableStudents = (await _studentChargeRepository.GetOutstanding()).GroupBy(sc => sc.StudentId);

            var generatedBills = new List <Bill>();

            foreach (var billableStudent in billableStudents)
            {
                var bill = new Bill
                {
                    CreatedDate = DateTime.Now,
                    StudentId   = billableStudent.Key,
                    DueDate     = DateTime.Today.AddMonths(paymentPeriodLength)
                };

                foreach (var charge in billableStudent)
                {
                    bill.BillCharges.Add(new BillCharge
                    {
                        ChargeId    = charge.ChargeId,
                        GrossAmount = charge.Charge.Amount
                    });

                    var chargeInDb = await _studentChargeRepository.GetByIdWithTracking(charge.ChargeId);

                    chargeInDb.Recurrences--;
                }

                var studentDiscounts = await _studentDiscountRepository.GetByStudent(billableStudent.Key);

                foreach (var studentDiscount in studentDiscounts)
                {
                    var applicableChargeIds =
                        (await _chargeDiscountRepository.GetByDiscount(studentDiscount.DiscountId)).Select(x =>
                                                                                                           x.ChargeId);

                    if (bill.BillCharges.Any(c => applicableChargeIds.Contains(c.ChargeId)))
                    {
                        bill.BillDiscounts.Add(new BillDiscount
                        {
                            DiscountId = studentDiscount.DiscountId,
                            Amount     = studentDiscount.Discount.Amount,
                            Percentage = studentDiscount.Discount.Percentage
                        });
                    }
                }

                _billRepository.Create(bill);
                generatedBills.Add(bill);
            }

            await _billRepository.SaveChanges();

            return(generatedBills.Select(BusinessMapper.Map <BillModel>));
        }