Example #1
0
        public static void SetCustomerExpiry(CustomerExpiry entity)
        {
            GenericRepository <Customer> rpcustomer = new GenericRepository <Customer>();
            var customer = rpcustomer.Find(entity.CustomerID);

            customer.ExpiryValue     += (entity.SaleTotalPrice - entity.PaidPrice);
            customer.PaidExpiryValue += entity.PaidPrice;
            rpcustomer.SaveChanges();
        }
        public ActionResult AddSale(SaleVM model)
        {
            var sepet = (CartVM)Session["Sepet"];

            if (sepet != null)
            {
                int userId = UserID();
                model.InvoiceDate = model.InvoiceDate.Year == 0001 ? DateTime.Now : model.InvoiceDate;
                Sale sale = new Sale()
                {
                    PaymentType = model.PaymentType,
                    UserID      = userId,
                    CustomerID  = model.CustomerID,
                    InvoiceDate = model.InvoiceDate,
                    ExpiryDate  = model.ExpiryDate.Year == 0001 ? DateTime.Now : model.ExpiryDate,
                    TotalPrice  = sepet.TotalSalePrice,
                    IsInvoiced  = model.Invoice == 1 ? true : false
                };
                var list = new List <SaleDetails>();
                foreach (var item in sepet.ProductList)
                {
                    SaleDetails detail = new SaleDetails()
                    {
                        ProductID     = item.ID,
                        KdvPrice      = Math.Round(item.KdvPrice, 2),
                        Quantity      = item.SaleCount,
                        Price         = Math.Round(item.UnitSalePrice, 2),
                        AddDate       = DateTime.Now,
                        IsPhone       = item.CategoryID == 6 || item.CategoryID == 7 ? true : false,
                        UnitSalePrice = item.UnitPrice,
                        CategoryID    = item.CategoryID
                    };
                    list.Add(detail);
                }
                sale.SaleDetails = list;
                rpsale.Add(sale);
                SetPaymentInfoforAdding(sale.SaleDetails, sepet.ProductList);

                if (model.PaymentType == "Vadeli")
                {
                    CustomerExpiry expiry = new CustomerExpiry()
                    {
                        ExpiryDate     = model.ExpiryDate,
                        CustomerID     = model.CustomerID,
                        PaidPrice      = model.PaidExpiryValue,
                        SaleID         = sale.ID,
                        SaleTotalPrice = sepet.TotalSalePrice
                    };
                    ExpiryService.SetCustomerExpiry(expiry);
                    rpcustomerexpiry.Add(expiry);
                    if (model.PaidExpiryValue != 0)
                    {
                        var expiryPayment = new ExpiryPayment
                        {
                            AdminUserID = UserID(),
                            PersonID    = model.CustomerID,
                            Price       = model.PaidExpiryValue
                        };
                        rpexpirypayment.Add(expiryPayment);
                    }
                }
                if (model.Invoice == 1)
                {
                    return(RedirectToAction("SetInvoice", model));
                }
                Session.Remove("Sepet");
            }
            return(RedirectToAction("Index"));
        }