Example #1
0
        //CancelBan
        public int Cancel(string id)
        {
            using (CoffeeEntities db = new CoffeeEntities())
            {
                if (id != null)
                {
                    int idHoaDonBanHang;
                    if (int.TryParse(id, out idHoaDonBanHang))
                    {
                        var hoadonBanHang = db.ORDER_HoaDonBanHang.Where(p => p.id == idHoaDonBanHang).FirstOrDefault();

                        if (hoadonBanHang != null)
                        {
                            var ban = db.DM_Ban.Where(p => p.id == hoadonBanHang.idBan).FirstOrDefault();

                            ban.trangthai = false;

                            db.SaveChanges();

                            return(1);
                        }
                    }
                }


                return(0);
            }
        }
        //we pass in the ItemID so that we can remove a certain object
        public ActionResult Contact(int ID)
        {
            CoffeeEntities ORM = new CoffeeEntities();
            //we build this object so that we can make a transaction
            DbContextTransaction DeleteCustomerTransaction = ORM.Database.BeginTransaction();
            Item temp = new Item();

            try
            {
                //we first find the specific item by the items id
                temp = ORM.Items.Find(ID);
                ORM.Items.Remove(temp);
                ORM.SaveChanges();
                DeleteCustomerTransaction.Commit();
                //if the remove was successful we commit the transaction
                ViewBag.Message = $"{temp.Description} was removed";
            }
            catch (Exception ex)
            {
                //if the remove was unsuccessful then we
                //roll back the transaction so no data is lost
                DeleteCustomerTransaction.Rollback();
                ViewBag.Message = "Item could not be removed";

                return(View());
            }

            return(View());
        }
Example #3
0
        public ActionResult ItemView(string Name)
        {
            CoffeeEntities ORM = new CoffeeEntities();

            //here I used a .Where method, and then I used a lambda function to find items for a specific customer
            ViewBag.Items = ORM.Items.Where(x => x.Name == Name).ToList();

            return(View());

            //This code is for looking up an item be description instead of customer email

            //way to find item by description
            //grab all items from the DB
            //List<Item> itemList = ORM.Items.ToList();
            ////make blank list to add specific items to
            //List<Item> newItems = new List<Item>();
            ////this loop will compare the items to the the description
            //foreach (Item I in itemList)
            //{
            //    if (I.Description == descrip)
            //    {
            //        newItems.Add(I);
            //    }
            //}
        }
Example #4
0
        public ActionResult AddItem(string Name = "", string Description = "", string Quantity = "", string Price = "")
        {
            CoffeeEntities orm = new CoffeeEntities();

            Item item = new Item();

            item.Name        = Name;
            item.Description = Description;
            item.Quantity    = Quantity;
            item.Price       = Price;

            if (ModelState.IsValid)
            {
                //if the model is valid then we add to our DB
                orm.Items.Add(item);
                //we have to save our changes or they won't stay in our DB
                orm.SaveChanges();
                //ViewBag.message = $"{item.Name} has been added";
            }
            else
            {
                ViewBag.message = "Item is not valid, cannot add to DB.";
            }

            ViewBag.Name        = Name;
            ViewBag.Description = Description;
            ViewBag.Quantity    = Quantity;
            ViewBag.Price       = Price;

            return(View());
        }
        public ActionResult Submission(User data)
        {
            CoffeeEntities ORM = new CoffeeEntities();

            if (ModelState.IsValid)
            {
                try
                {
                    ORM.Users.Add(data);
                    ORM.SaveChanges();
                    ViewBag.message = $"All information has been added";
                }
                catch (Exception e)
                {
                    ViewBag.message = $"error! {e.Message}";

                    return(View());
                }
            }
            else
            {
                ViewBag.message = $" User information is not valid, cannot add to DB";
            }

            return(View());
        }
Example #6
0
        public ActionResult MenuSorted(string column)
        {
            CoffeeEntities db = new CoffeeEntities();

            if (column == "Name")
            {
                ViewBag.Items = (from i in db.Items
                                 orderby i.Name
                                 select i).ToList();
            }
            else if (column == "Description")
            {
                ViewBag.Items = (from i in db.Items
                                 orderby i.Description
                                 select i).ToList();
            }
            else if (column == "Stock")
            {
                ViewBag.Items = (from i in db.Items
                                 orderby i.Stock
                                 select i).ToList();
            }
            else if (column == "Price")
            {
                ViewBag.Items = (from i in db.Items
                                 orderby i.Price
                                 select i).ToList();
            }
            return(View("Menu"));
        }
Example #7
0
        //Delete
        public int Delete(string id)
        {
            using (CoffeeEntities db = new CoffeeEntities())
            {
                if (id != null)
                {
                    int idXuatHang;
                    if (int.TryParse(id, out idXuatHang))
                    {
                        //Delte ChiTiet
                        var chitiets = db.KT_ChiTietXuatHang.Where(p => p.idXuatHang == idXuatHang);
                        if (chitiets.Count() > 0)
                        {
                            db.KT_ChiTietXuatHang.RemoveRange(chitiets);
                        }

                        var xuathang = db.KT_XuatHang.Where(p => p.id == idXuatHang).FirstOrDefault();
                        db.KT_XuatHang.Remove(xuathang);

                        db.SaveChanges();

                        return(1);
                    }
                }

                return(0);
            }
        }
Example #8
0
 //XuatHang
 public int XuatHang(string id)
 {
     using (CoffeeEntities db = new CoffeeEntities())
     {
         if (id != "")
         {
             int idChiTietXuatHang;
             if (int.TryParse(id, out idChiTietXuatHang))
             {
                 var chitietXuatHang = db.KT_ChiTietXuatHang.Where(p => p.id == idChiTietXuatHang).FirstOrDefault();
                 if (chitietXuatHang != null)
                 {
                     var mathang = db.DM_MatHang.Where(p => p.id == chitietXuatHang.idMatHang).FirstOrDefault();
                     if (mathang != null)
                     {
                         mathang.ton -= chitietXuatHang.soluong;
                     }
                     db.SaveChanges();
                     return(1);
                 }
             }
         }
         return(0);
     }
 }
Example #9
0
        public ActionResult Index()
        {
            CoffeeEntities orm = new CoffeeEntities();

            ViewBag.Items = orm.Items.ToList();
            return(View());
        }
Example #10
0
        //this link is on the registration page
        //which sends the user input here
        //and then displays the view named Welcome
        //public ActionResult Welcome(int input = 0)
        //{
        //    ViewBag.data = input;
        //    return View();
        //}

        //parameters are automatically parsed in from query string
        public ActionResult Register(string Name = "", string CoffeeType = "", string Drinkware = "")
        {
            CoffeeEntities orm = new CoffeeEntities();


            User user = new User();

            user.Name       = Name;
            user.CoffeeType = CoffeeType;
            user.Drinkware  = Drinkware;

            if (ModelState.IsValid)
            {
                //if the model is valid then we add to our DB
                orm.Users.Add(user);
                //we have to save our changes or they won't stay in our DB
                orm.SaveChanges();
                ViewBag.message = $"{user.Name} has been added";
            }
            else
            {
                ViewBag.message = "Item is not valid, cannot add to DB.";
            }


            ViewBag.Name       = Name;
            ViewBag.CoffeeType = CoffeeType;
            ViewBag.Drinkware  = Drinkware;


            return(View());
        }
Example #11
0
        //DeleteChiTiet
        public int DeleteChiTiet(string id)
        {
            using (CoffeeEntities db = new CoffeeEntities())
            {
                if (id != null)
                {
                    int idHoaDonBanHang;
                    if (int.TryParse(id, out idHoaDonBanHang))
                    {
                        var hoadonBanHang = db.ORDER_HoaDonBanHang.Where(p => p.id == idHoaDonBanHang).FirstOrDefault();

                        if (hoadonBanHang != null)
                        {
                            var chitietThucDons  = db.ORDER_ChiTietHoaDonBanHang.Where(p => p.idHoaDonBanHang == hoadonBanHang.id);
                            var chitietNhanViens = db.ORDER_ChiTietNhanVienHoaDonBanHang.Where(p => p.idHoaDonBanHang == hoadonBanHang.id);

                            db.ORDER_ChiTietHoaDonBanHang.RemoveRange(chitietThucDons);
                            db.ORDER_ChiTietNhanVienHoaDonBanHang.RemoveRange(chitietNhanViens);

                            db.SaveChanges();

                            return(1);
                        }
                    }
                }

                return(0);
            }
        }
        public ActionResult Add(int id)
        {
            CoffeeEntities db = new CoffeeEntities();

            //check if the Cart object already exists
            if (Session["Cart"] == null)
            {
                List <Item> cart = new List <Item>();
                cart.Add((from i in db.item
                          where i.ID == id
                          select i).Single());

                Session.Add("Cart", cart);
            }
            else
            {
                //if it does exist, get the list
                List <Item> cart = (List <Item>)(Session["Cart"]);
                //add this book to it
                cart.Add((from i in db.item
                          where i.ID == id
                          select i).Single());
                //(add it back to the session)
                Session["Cart"] = cart;
            }
            return(View());
        }
Example #13
0
        public ActionResult ItemNameView(string Name)
        {
            CoffeeEntities ORM = new CoffeeEntities();

            ViewBag.Items = ORM.Items.Where(x => x.Name == Name).ToList();

            return(View());
        }
Example #14
0
        public ActionResult Users()
        {
            CoffeeEntities ORM = new CoffeeEntities();

            ViewBag.Users = ORM.Users.ToList();

            return(View());
        }
        public ActionResult ItemView()
        {
            CoffeeEntities db    = new CoffeeEntities();
            List <Item>    items = db.Items.ToList();

            ViewBag.Items = items;

            return(View());
        }
        public ActionResult Menu()
        {
            CoffeeEntities db    = new CoffeeEntities();
            List <Item>    items = db.item.ToList();

            ViewBag.Items = items;

            ViewBag.Statuses = db.item.ToList();

            return(View());
        }
Example #17
0
        public ActionResult About(int ID)
        {
            CoffeeEntities orm = new CoffeeEntities();

            ViewBag.Message = "The GC Coffee Shop is a new cafe epicenter in the city of Detroit. We strive to provide the best quality of robust coffee so that you are ready to accomplish the day with enthusiasm! Our web app now available, offers our clients the perks of free coffee and other cool prizes when registered. All it takes is a few seconds before your next free cup of espresso!";
            Item item = new Item();

            item = (Item)orm.Items.Where(x => x.ID == ID);

            return(View());
        }
Example #18
0
        public ActionResult Index()
        {
            //build our ORM Object Relational Mapping
            CoffeeEntities ORM = new CoffeeEntities();

            //these lines of code grab the data from our DB by using the ORM
            //I use the ToList() to make the data a list we can later index through
            ViewBag.Items = ORM.Items.ToList();
            ViewBag.Users = ORM.Users.ToList();


            return(View());
        }
Example #19
0
        // GET: BanHang
        public JsonResult Init()
        {
            using (CoffeeEntities db = new CoffeeEntities())
            {
                InitModelViewBanHang model = new InitModelViewBanHang();

                model.Bans    = db.DM_Ban.OrderBy(p => p.idKhuVuc).ThenBy(p => p.ten).ToList();
                model.KhuVucs = db.DM_KhuVuc.ToList();


                return(Json(model, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult MenuByName(string name)
        {
            CoffeeEntities db = new CoffeeEntities();
            //LINQ Query
            List <Item> items = (from i in db.item
                                 where i.Name == name
                                 select i).ToList();

            ViewBag.Name = items;

            ViewBag.Name = db.item.ToList();

            return(View("Menu"));
        }
        public ActionResult MenuByDescription(string description)
        {
            CoffeeEntities db = new CoffeeEntities();
            //LINQ Query
            List <Item> items = (from i in db.item
                                 where i.Description.Contains(description)
                                 select i).ToList();

            ViewBag.Items = items;

            ViewBag.Names = db.item.ToList();

            return(View("Menu"));
        }
Example #22
0
        public ActionResult Add(int id = 0)/*, int quantity = 0)*/
        {
            //dao.UpdateQuantity(id, quantity);
            CoffeeEntities db = new CoffeeEntities();

            if (id == 0 && Session["Cart"] != null)
            {
                //List<Item> cart = (List<Item>)(Session["Cart"]);
                //Item item = ()
                return(View("Add", Session["Cart"]));
            }
            else if (id == 0)
            {
                //List<Item> cart = (List<Item>)(Session["Cart"]);
                //Item item = ()
                return(View("Add", Session["Cart"] = null));
            }
            else
            {
                //Check if the Cart already exists
                if (Session["Cart"] == null)
                {
                    //if it doesn't make a new list of books

                    List <Item> cart = new List <Item>();
                    //add this book to it
                    cart.Add((from i in db.Items
                              where i.ItemId == id
                              select i).Single());

                    //add the list to the session
                    Session.Add("Cart", cart);
                }
                else
                {
                    //if it does exist need to get the list
                    List <Item> cart = (List <Item>)(Session["Cart"]);
                    //add this book to the list
                    cart.Add((from b in db.Items
                              where b.ItemId == id
                              select b).Single());
                    //add the list to the session
                    //Session["Cart"] = cart;
                }

                return(View());
            }
        }
Example #23
0
        public JsonResult GetDropDownUser()
        {
            using (CoffeeEntities db = new CoffeeEntities())
            {
                var model = (
                    from p in db.AspNetUsers
                    select new DropDownItemUser()
                {
                    Id = p.Id,
                    UserName = p.UserName
                }
                    ).ToList();

                return(Json(model, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult CoffeeRegistration(User data)
        {
            CoffeeEntities ORM = new CoffeeEntities();

            if (ModelState.IsValid)
            {
                ORM.Users.Add(data);
                ORM.SaveChanges();
                ViewBag.message = $"{data.FirstName}, you have been added!";
            }
            else
            {
                ViewBag.message = "Item is not valid, cannot add to DB.";
            }
            return(View());
        }
        public ActionResult About(Item data)
        {
            CoffeeEntities ORM = new CoffeeEntities();

            if (ModelState.IsValid)
            {
                ORM.Items.Add(data);

                ORM.SaveChanges();
                ViewBag.message = $"{data.Description} has been added";
            }
            else
            {
                ViewBag.message = "Item is not valid, cannot add to DB.";
            }

            return(View());
        }
Example #26
0
        //DeleteByThucDon
        public int DeleteByThucDon(string id)
        {
            using (CoffeeEntities db = new CoffeeEntities())
            {
                if (id != "")
                {
                    int idThucDon;
                    if (int.TryParse(id, out idThucDon))
                    {
                        var dinhluongs = db.KT_DinhLuong.Where(p => p.idThucDon == idThucDon);
                        db.KT_DinhLuong.RemoveRange(dinhluongs);
                        db.SaveChanges();
                        return(1);
                    }
                }

                return(0);
            }
        }
Example #27
0
        public ActionResult RegSuccess(User data)
        {
            CoffeeEntities ORM = new CoffeeEntities();

            ViewBag.Users = ORM.Users.ToList();

            if (ModelState.IsValid)
            {
                ORM.Users.Add(data);
                ORM.SaveChanges();
                ViewBag.message = $"{data.FirstName} has been added";
            }
            else
            {
                ViewBag.message = "Item is not valid, cannot add to DB.";
            }

            return(View());
        }
Example #28
0
        //ThanhToan
        public int ThanhToan(string id)
        {
            using (CoffeeEntities db = new CoffeeEntities())
            {
                if (id != null)
                {
                    int idHoaDonBanHang;
                    if (int.TryParse(id, out idHoaDonBanHang))
                    {
                        var hoadonBanHang = db.ORDER_HoaDonBanHang.Where(p => p.id == idHoaDonBanHang).FirstOrDefault();
                        if (hoadonBanHang != null)
                        {
                            hoadonBanHang.isThanhToan = true;
                            var ban = db.DM_Ban.Where(p => p.id == hoadonBanHang.idBan).FirstOrDefault();
                            ban.trangthai = false;

                            //Trừ mặt hàng, tính tiền vốn
                            var   chitiets = db.ORDER_ChiTietHoaDonBanHang.Where(p => p.idHoaDonBanHang == hoadonBanHang.id);
                            float tienVon  = 0;
                            foreach (var chitiet in chitiets)
                            {
                                var dinhluongs = db.KT_DinhLuong.Where(p => p.idThucDon == chitiet.idThucDon);
                                foreach (var dinhluong in dinhluongs)
                                {
                                    var mathang = db.DM_MatHang.Where(p => p.id == dinhluong.idMatHang).FirstOrDefault();
                                    tienVon    += float.Parse((mathang.dongia * dinhluong.soluong * chitiet.soluong).ToString());
                                    mathang.ton = mathang.ton - (dinhluong.soluong * chitiet.soluong);
                                }
                            }

                            hoadonBanHang.tienVon = tienVon;

                            db.SaveChanges();

                            return(1);
                        }
                    }
                }

                return(0);
            }
        }
Example #29
0
        //GetChiTiet
        public JsonResult GetChiTiet(string id)
        {
            using (CoffeeEntities db = new CoffeeEntities())
            {
                if (id != null)
                {
                    int idHoaDonBanHang;
                    if (int.TryParse(id, out idHoaDonBanHang))
                    {
                        ChiTiet model = new ChiTiet();
                        model.ChiTietThucDons  = db.ORDER_ChiTietHoaDonBanHang.Where(p => p.idHoaDonBanHang == idHoaDonBanHang).ToList();
                        model.ChiTietNhanViens = db.ORDER_ChiTietNhanVienHoaDonBanHang.Where(p => p.idHoaDonBanHang == idHoaDonBanHang).ToList();

                        return(Json(model, JsonRequestBehavior.AllowGet));
                    }
                }

                return(null);
            }
        }
Example #30
0
        //we pass in the item data so that we can add the new item to our DB
        public ActionResult About(Item data)
        {
            CoffeeEntities ORM = new CoffeeEntities();

            //we check to make sure the Item Model that we passed in is Valid
            if (ModelState.IsValid)
            {
                //if the model is valid then we add to our DB
                ORM.Items.Add(data);
                //we have to save our changes or they won't stay in our DB
                ORM.SaveChanges();
                ViewBag.message = $"{data.Description} has been added";
            }
            else
            {
                ViewBag.message = "Item is not valid, cannot add to DB.";
            }

            return(View());
        }