Exemple #1
0
        public List <CustomerPurchase> CustomerPurchaseLists(DateTime datefrom, DateTime dateto)
        {
            var x = pEntity.customer_sales_date(datefrom, dateto);
            List <CustomerPurchase> cus = new List <CustomerPurchase>();

            foreach (customer_sales_date_Result a in x)
            {
                CustomerPurchase cp = new CustomerPurchase();

                cp.Firstname          = a.Firstname;
                cp.Lastname           = a.Lastname;
                cp.productcode        = a.productcode;
                cp.ProductDescription = a.ProductDescription;
                cp.ProductName        = a.ProductName;
                cp.QTY         = a.QTY;
                cp.RetailPrice = a.RetailPrice;
                cp.sales_id    = a.sales_id;
                cp.TotalAmount = a.TotalAmount;
                cp.unitWeight  = a.unitWeight;
                cp.Weight      = a.Weight;
                cp.measurement = a.measurement;
                cp.referenceNo = a.referenceNo;

                cus.Add(cp);
            }
            return(cus);
        }
        static void Main(string[] args)
        {
            if (args == null)
            {
                return;
            }

            var serviceProvider = new ServiceCollection()
                                  .AddTransient <IDiscountProvider, DiscountProvider>()
                                  .AddTransient <IDiscountManager, DiscountManager>()
                                  .AddTransient <IPurchaseManager, PurchaseManager>()
                                  .BuildServiceProvider();

            var purchase = new CustomerPurchase();
            var prices   = new Dictionary <ItemType, double>()
            {
                { ItemType.Apple, 0.5 },
                { ItemType.Banana, 0.7 },
                { ItemType.Orange, 0.45 },
            };

            foreach (var item in args)
            {
                if (Enum.TryParse(item, out ItemType type) &&
                    prices.TryGetValue(type, out double price))
                {
                    purchase.AddItem(new PurchasedItem(type, price));
                }
            }

            var total = serviceProvider.GetService <IPurchaseManager>().GetPurchaseTotal(purchase);

            Console.WriteLine($"The total of purchases is: {total} pounds");
            Console.ReadKey();
        }
Exemple #3
0
        // GET: Checkout
        public ActionResult Check()
        {
            List <Product> purchases = (List <Product>)Session["cart"]; // add session["cart"] products to list

            using (var db = new ShoppingCartDbContext())
            {
                if (Session["SessionId"] != null)//check if sessionId is null
                {
                    string   SessionId = (string)Session["SessionId"];
                    Customer customer  = db.Customer.Where(x => x.SessionId == SessionId).FirstOrDefault(); // retrieve customer based on SessionId

                    double   currentTime = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
                    DateTime dateTimeNow = new DateTime(1970, 1, 1);
                    dateTimeNow = dateTimeNow.AddSeconds(currentTime);
                    string dateNow = dateTimeNow.ToString("dd MMMM yyyy"); //convert datetime to string (from seconds)
                    foreach (var purchase in purchases)
                    {
                        CustomerPurchase cp = new CustomerPurchase();
                        cp.CustomerId     = customer.Id;
                        cp.ProductId      = purchase.Id;
                        cp.ActivationCode = Guid.NewGuid().ToString();
                        cp.DatePurchased  = dateNow;
                        cp.Customer       = customer;
                        cp.Product        = purchase;
                        db.CustomerPurchase.Add(cp); // add customer puchases to DB
                    }
                    db.SaveChanges();                //Save changes
                }
                Session["cart"]  = null;             // after successful purchase empty cart
                Session["count"] = 0;                // empty count of cart
                return(RedirectToAction("Mypurchases"));
            }
        }
Exemple #4
0
        public ActionResult Checkout(string SessionId)
        {
            if (!Util.SessionExist(SessionId))
            {
                return(RedirectToAction("Login", "Login"));
            }

            //get current time
            int      curUnix  = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
            Customer customer = Util.GetCustomerBySessionId(SessionId);

            //For each item in the cart, add to customer purchased under the user
            TempCart Cart = (TempCart)Session[SessionId];

            using (var db = new ShoppingCartDbContext())
            {
                foreach (CartItem item in Cart.Items)
                {
                    for (int i = 0; i < item.Quantity; i++)
                    {
                        CustomerPurchase purchase = new CustomerPurchase();
                        purchase.CustomerId     = customer.Id;
                        purchase.ProductId      = item.Id;
                        purchase.DatePurchased  = curUnix;
                        purchase.ActivationCode = Guid.NewGuid().ToString();
                        db.CustomerPurchase.Add(purchase);
                    }
                }
                db.SaveChanges();
            }

            //Cart has been checked out, remove old cart, reset cart and redirect to view purchase
            Session[SessionId] = new TempCart();
            return(RedirectToAction("MyPurchase", "ViewPurchase", new { SessionId }));
        }
Exemple #5
0
        public ActionResult Delete_P(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShopTymDBContext context = new ShopTymDBContext();
            CustomerPurchase items   = context.CustomerPurchases.SingleOrDefault(s => s.PurchaseId == id);

            return(View(items));
        }
Exemple #6
0
        public ActionResult Delete_PP(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ShopTymDBContext context = new ShopTymDBContext();
            CustomerPurchase item    = context.CustomerPurchases.SingleOrDefault(s => s.PurchaseId == id);

            context.CustomerPurchases.Remove(item);
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CustomerPurchase = await _context.CustomerPurchases
                               .Include(c => c.Book)
                               .Include(c => c.Customer).FirstOrDefaultAsync(m => m.Id == id);

            if (CustomerPurchase == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CustomerPurchase = await _context.CustomerPurchases.FindAsync(id);

            if (CustomerPurchase != null)
            {
                _context.CustomerPurchases.Remove(CustomerPurchase);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CustomerPurchase = await _context.CustomerPurchases
                               .Include(c => c.Book)
                               .Include(c => c.Customer).FirstOrDefaultAsync(m => m.Id == id);

            if (CustomerPurchase == null)
            {
                return(NotFound());
            }
            ViewData["BookId"]     = new SelectList(_context.Books, "Id", "Id");
            ViewData["CustomerId"] = new SelectList(_context.Customers, "Id", "Id");
            return(Page());
        }
        public Boolean insertCustomerPurchase(String clientName, String productName, int quantity, int totalPay)
        {
            Boolean ret = false; // return variable

            try
            {
                MongoClient     mc = new MongoClient("mongodb://*****:*****@ds139428.mlab.com:39428/info_aplicada_ucr");
                MongoServer     ms = mc.GetServer();
                MongoDatabase   db = ms.GetDatabase("info_aplicada_ucr");
                var             customerPurchase = new CustomerPurchase(clientName, productName, quantity, totalPay);
                MongoCollection collection       = db.GetCollection <CustomerPurchase>("Client_Report");
                collection.Insert <CustomerPurchase>(customerPurchase);
                ret = true;
            }//try
            catch (Exception error)
            {
                ret = false;
            } //catch
            return(ret);
        }     //insertCustomerPurchase
 public CustomerPurchaseTests()
 {
     _purchase = new CustomerPurchase();
 }
 public PurchaseManagerTests()
 {
     _purchase        = new CustomerPurchase();
     _discountManager = new DiscountManager(new TestDiscountProvider());
     _purchaseManager = new PurchaseManager(_discountManager);
 }