Example #1
0
        // GET: Admin
        public ActionResult Index()
        {
            using (MEContext context = new MEContext())
            {
                var list = context.Purchases.OrderBy(x => x.Id).ToList();
                int re   = 0;
                foreach (var item in list)
                {
                    var      holder = "";
                    string   phrase = item.ProductId;
                    string[] idSp   = phrase.Split(',');
                    foreach (var x in idSp)
                    {
                        var y = context.Products.Find(int.Parse(x));
                        if (y != null)
                        {
                            holder = holder + y.Name + ", ";
                        }
                        else
                        {
                            holder = holder + "Removed product, ";
                        }
                    }
                    list[re].ProductId = holder;
                    re++;
                }

                return(View(list));
            }
        }
Example #2
0
        public ActionResult Checkout(Purchases obj)
        {
            if (obj == null)
            {
                Response.Redirect("Index");
            }
            List <Item> cart = (List <Item>)Session["cart"];

            List <string> products = new List <string>();

            for (int i = 0; i < cart.Count; i++)
            {
                products.Add(cart[i].Product.Id.ToString());
            }
            string prodIdString = string.Join(",", products.ToArray());

            try
            {
                using (MEContext context = new MEContext())
                {
                    obj.CustomerId    = User.Identity.GetUserId();
                    obj.CustomerEmail = User.Identity.GetUserName();
                    obj.ProductId     = prodIdString;
                    obj.PurchaseDate  = DateTime.Now;
                    context.Purchases.Add(obj);
                    context.SaveChanges();
                    Session["cart"] = null;
                    return(Redirect("~/Home/Index/"));
                }
            }
            catch
            {
                return(View());
            }
        }
 // GET: Product/Details/5
 public ActionResult Details(int id)
 {
     using (MEContext context = new MEContext())
     {
         var display = context.Products.Find(id);
         return(View(display));
     }
 }
 // GET: Product
 public ActionResult Index()
 {
     using (MEContext context = new MEContext())
     {
         var list = context.Products.OrderBy(x => x.Id).ToList();
         return(View(list));
     }
 }
Example #5
0
        // GET: Admin/Edit/5
        public ActionResult Edit(int id)
        {
            Product result = null;

            using (MEContext context = new MEContext())
            {
                result = context.Products.Find(id);
            }
            return(View(result));
        }
Example #6
0
        private static void Teste1()
        {
            var opt = new DbContextOptionsBuilder <MEContext>();

            opt.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=MaterialEscolarDb;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");

            using (var contexto = new MEContext(opt.Options))
            {
                var prod1 = new Produto {
                    Id = 1, Nome = "novo nome"
                };

                contexto.Entry(prod1).State = EntityState.Modified;
                contexto.SaveChanges();
            }
        }
Example #7
0
 public ActionResult Create(Product obj)
 {
     try
     {
         using (MEContext context = new MEContext())
         {
             context.Products.Add(obj);
             context.SaveChanges();
             return(Redirect("~/Product/Index"));
         }
     }
     catch
     {
         return(View());
     }
 }
Example #8
0
 public ActionResult Edit(int id, FormCollection collection)
 {
     try
     {
         using (MEContext context = new MEContext())
         {
             var c = context.Products.Find(id);
             TryUpdateModel(c);
             context.SaveChanges();
             return(Redirect("~/Product/Index"));
         }
     }
     catch
     {
         return(View());
     }
 }
Example #9
0
        public ActionResult Buy(int id)
        {
            using (MEContext context = new MEContext())
            {
                if (Session["cart"] == null)
                {
                    List <Item> cart = new List <Item>();
                    cart.Add(new Item {
                        Product = context.Products.Find(id), Quanity = 1
                    });
                    Session["cart"] = cart;
                }
                else
                {
                    List <Item> cart  = (List <Item>)Session["cart"];
                    int         index = isExist(id);
                    if (index != -1)
                    {
                        cart[index].Quanity++;
                    }
                    else
                    {
                        cart.Add(new Item {
                            Product = context.Products.Find(id), Quanity = 1
                        });
                    }
                    Session["cart"] = cart;
                }

                var toChange = context.Products.Find(id);
                toChange.Qty -= 1;

                context.Entry(toChange).State = EntityState.Modified;
                context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Example #10
0
        public ActionResult Remove(int id)
        {
            List <Item> cart       = (List <Item>)Session["cart"];
            int         index      = isExist(id);
            int         removedQty = cart[index].Quanity;

            cart.RemoveAt(index);
            if (cart.Count == 0)
            {
                cart = null;
            }
            Session["cart"] = cart;
            using (MEContext context = new MEContext())
            {
                var toChange = context.Products.Find(id);
                toChange.Qty += removedQty;

                context.Entry(toChange).State = EntityState.Modified;
                context.SaveChanges();
            }


            return(RedirectToAction("Index"));
        }
Example #11
0
 public KitRepository(MEContext context) : base(context)
 {
 }
Example #12
0
 public EntityBaseRepository(MEContext context)
 {
     DbContext = context;
 }