public Guid AddProduct(Product p)
 {
     //Shopping
     _context.Products.Add(p);
     _context.SaveChanges(); //Saves permanently into the database
     return(p.ID);
 }
Example #2
0
        public Guid AddCart(Cart c)
        {
            _context.Carts.Add(c);
            _context.SaveChanges();

            return(c.Id);
        }
Example #3
0
        public Guid CreateOrder(Order o)
        {
            _context.Orders.Add(o);
            _context.SaveChanges();

            return(o.Id);
        }
        public void AddProduct(Product p)
        {
            //context has a list of products and I need to add p..adding to the local list of products my new product

            _context.Products.Add(p);
            _context.SaveChanges();
        }
Example #5
0
 public Guid AddProduct(Product p)
 {
     //ShoppingCartDbContext context = new ShoppingCartDbContext();
     _context.Products.Add(p);
     _context.SaveChanges();
     return(p.Id);
 }
        public Guid AddTask(Task task)
        {
            task.id = Guid.NewGuid();
            _context.Tasks.Add(task);
            _context.SaveChanges();

            return(task.id);
        }
        public Guid AddComment(Comment comment)
        {
            comment.id = Guid.NewGuid();
            _context.Comments.Add(comment);
            _context.SaveChanges();

            return(comment.id);
        }
Example #8
0
        public Guid AddComment(Comment c)
        {
            c.Id = Guid.NewGuid();
            _context.Comments.Add(c);
            _context.SaveChanges();

            return(c.Id);
        }
        public int AddProductToCart(Cart newCartEntry)
        {
            //Creates a new cart entry to add under the current user

            _context.Carts.Add(newCartEntry);
            _context.SaveChanges(); //Saves permanently into the database
            return(newCartEntry.Id);
        }
        public Guid AddTask(Task t)
        {
            t.Id = Guid.NewGuid();
            _context.Tasks.Add(t);
            _context.SaveChanges();

            return(t.Id);
        }
Example #11
0
        public Guid AddSubmission(Submission s)
        {
            s.Id = Guid.NewGuid();
            _context.Submissions.Add(s);
            _context.SaveChanges();

            return(s.Id);
        }
        public Guid AddProduct(Product p)
        {
            // p.Category = null; //because the runtime thinks that it needs to add a new category

            _context.Products.Add(p);
            _context.SaveChanges();

            return(p.Id);
        }
        public Guid AddProduct(Product p)
        {
            // p.Category = null; //because the runtime thinks that the Catergory needs to be added as well.

            //to add a product
            _context.Products.Add(p);
            _context.SaveChanges();

            return(p.Id);
        }
        public void Edited(ItemCategoryDTO obj)
        {
            ItemCategory EditedCategory = _db.ItemCategories.Where(x => x.ItemCategoryId == obj.ItemCategoryId).FirstOrDefault();

            EditedCategory.ItemCategoryId   = obj.ItemCategoryId;
            EditedCategory.ItemCategoryName = obj.ItemCategoryName;
            EditedCategory.SignUpId         = obj.SignUpId;
            _db.Entry(EditedCategory).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _db.SaveChanges();
        }
Example #15
0
 public int AddOrderDetails(OrderDetails o)
 {
     o.OrderFK   = o.Order.Id;
     o.ProductFk = o.Product.Id;
     o.Order     = null;
     o.Product   = null;
     _context.OrderDetails.Add(o);
     _context.SaveChanges();
     return(o.Id);
 }
 public bool Add(Manufacturer t)
 {
     try
     {
         this._shoppingCartDbContext.Manufacturers.Add(t);
         _shoppingCartDbContext.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #17
0
 public Guid AddToCart(Cart c)
 {
     try
     {
         _context.Carts.Add(c);
         _context.SaveChanges();
         return(c.Id);
     }
     catch (Exception e)
     {
         return(Guid.NewGuid());
     }
 }
Example #18
0
        public void AddMoreShopDetail(MoreDetailDTO obj)
        {
            MoreDetail SaveMoreDetail = new MoreDetail();

            SaveMoreDetail.AdditionAddress     = obj.AdditionAddress;
            SaveMoreDetail.AdditionPhoneNumber = obj.AdditionPhoneNumber;
            SaveMoreDetail.ImageUrl            = obj.ImageUrl;
            SaveMoreDetail.Location            = obj.Location;
            SaveMoreDetail.SignUpId            = obj.SignUpId;

            _db.MoreDetails.Add(SaveMoreDetail);
            _db.SaveChanges();
        }
        public void setAllLoginData(SignUpDTO signobj)
        {
            try
            {
                SignUp obj = new SignUp();
                obj.Address     = signobj.Address;
                obj.Email       = signobj.Email;
                obj.FullName    = signobj.FullName;
                obj.LoginType   = signobj.LoginType;
                obj.Password    = signobj.Password;
                obj.PhoneNumber = signobj.PhoneNumber;

                if (obj.LoginType == "User")
                {
                    obj.Active = true;
                }
                else
                {
                    obj.Active = false;
                }
                _db.SignUps.Add(obj);
                _db.SaveChanges();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #20
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 }));
        }
        public int Checkout(OrderDetail od)
        {
            _context.OrderDetails.Add(od);
            _context.SaveChanges();

            return(od.Id);
        }
Example #22
0
        public ActionResult CheckOut()
        {
            int totalPrice = 0;

            foreach (Cart cart in LocalData.Cart)
            {
                totalPrice += Int32.Parse(cart.Product.Price) * cart.Amount;
            }

            Order order = new Order
            {
                Paid  = false,
                Price = totalPrice.ToString()
            };

            _dbContex.Order.Add(order);

            foreach (Cart cart in LocalData.Cart)
            {
                OrderDetails orderDetails = new OrderDetails
                {
                    OrderId   = order.Id,
                    ProductId = cart.Product.Id,
                    Amount    = cart.Amount
                };

                _dbContex.OrderDetails.Add(orderDetails);
            }

            _dbContex.SaveChanges();
            LocalData.Cart.Clear();
            Message = "Your order has been placed. Your order ID is: " + order.Id;

            return(RedirectToAction("Index"));
        }
        public Guid CreateOrderDetails(OrderDetail od)
        {
            _context.OrderDetails.Add(od);
            _context.SaveChanges();

            return(od.Id);
        }
Example #24
0
        public void AddTask(Task assigned)
        {
            _context.Task.Add(assigned);

            _context.SaveChanges();
            //return assigned.taskId;
        }
Example #25
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"));
            }
        }
Example #26
0
    public static void Initialize(IServiceProvider serviceProvider)
    {
        using (var context = new ShoppingCartDbContext(
                   serviceProvider.GetRequiredService <DbContextOptions <ShoppingCartDbContext> >()))
        {
            #region PaymentOption
            if (!context.PaymentMethods.Any())
            {
                context.PaymentMethods.AddRange(
                    new PaymentMethod()
                {
                    Name            = "Mpesa",
                    PaymentMethodId = Guid.Parse("816f2387-147e-4bc5-812e-b45cdd862238")
                },

                    new PaymentMethod()
                {
                    Name            = "Cash on delivery",
                    PaymentMethodId = Guid.Parse("866f8387-147e-4bc5-812e-b45cdd862238")
                }
                    );
            }
            #endregion PaymentOption
            context.SaveChanges();
        }
    }
Example #27
0
        public void EditDetails(SignUpDTO obj)
        {
            SignUp signupobj = _db.SignUps.Where(x => x.SignUpId == obj.SignUpId).FirstOrDefault();

            signupobj.Active      = obj.Active;
            signupobj.Address     = obj.Address;
            signupobj.Email       = obj.Email;
            signupobj.FullName    = obj.FullName;
            signupobj.LoginType   = obj.LoginType;
            signupobj.Password    = obj.Password;
            signupobj.PhoneNumber = obj.PhoneNumber;
            signupobj.SignUpId    = obj.SignUpId;

            _db.Entry(signupobj).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            _db.SaveChanges();
        }
Example #28
0
        public ActionResult Init()
        {
            Product product = _dbContext.Products.FirstOrDefault();

            if (product == null)
            {
                int    count = 0;
                int    price = 50;
                string name  = "My Product";

                while (count < 12)
                {
                    Product p = new Product
                    {
                        Name = name + (count + 1)
                    };

                    price   = (price + (count * 20));
                    p.Price = price.ToString();

                    _dbContext.Products.Add(p);
                    _dbContext.SaveChanges();

                    count++;
                }
            }

            return(RedirectToAction("Index"));
        }
    public static void Initialize(IServiceProvider serviceProvider)
    {
        using (var context = new ShoppingCartDbContext(
                   serviceProvider.GetRequiredService <DbContextOptions <ShoppingCartDbContext> >()))
        {
            #region ShipmentMethod
            if (!context.ShipmentMethods.Any())
            {
                context.ShipmentMethods.AddRange(
                    new ShipmentMethod()
                {
                    Name             = "Self pick up",
                    ShipmentMethodId = Guid.Parse("866f8387-147e-4bc5-812e-b45cdd862238")
                },
                    new ShipmentMethod()
                {
                    Name             = "Default shipment method",
                    ShipmentMethodId = Guid.Parse("866f3387-147e-4bc5-812e-b45c8d862238")
                }
                    );
            }
            #endregion ShipmentMethod

            context.SaveChanges();
        }
    }
 // GET: Login
 public ActionResult Login(string username, string password)
 {
     if (HttpContext.Request.HttpMethod == "POST")
     {
         var  db   = new ShoppingCartDbContext();
         User user = db.User.Where(x => x.Username == username).FirstOrDefault();
         if (user == null)
         {
             return(RedirectToAction("Login"));
         }
         var    sha1         = new SHA1CryptoServiceProvider();
         string passwordHash = Convert.ToBase64String(sha1.ComputeHash(Encoding.UTF8.GetBytes(password)));
         if (user.Username == username && user.Password == passwordHash)
         {
             Session session = new Session(user);
             Response.Cookies["ShoppingCart_Team7B"]["sessionId"] = session.SessionId;
             db.Session.Add(session);
             db.SaveChanges();
             return(RedirectToAction("ListProducts", "Product"));
         }
         else
         {
             return(RedirectToAction("Login"));
         }
     }
     return(View());
 }