Esempio n. 1
0
        public ActionResult Create()
        {
            Cat_Pro_Bra_viewModel vM = new Cat_Pro_Bra_viewModel();

            vM.Categories = db.categories.ToList();
            return(View(vM));
        }
        public ActionResult searching()
        {
            Cat_Pro_Bra_viewModel GVM = new Cat_Pro_Bra_viewModel();

            GVM.Products = con.products.ToList();
            return(View(GVM));
        }
        public ActionResult create()
        {
            Cat_Pro_Bra_viewModel sss = new Cat_Pro_Bra_viewModel();

            sss.Categories = db.categories.ToList();
            sss.Brands     = db.brands.ToList();
            return(View(sss));
        }
Esempio n. 4
0
        public ActionResult Index()
        {
            Cat_Pro_Bra_viewModel vM = new Cat_Pro_Bra_viewModel();

            vM.Brands     = db.brands.ToList();
            vM.Categories = db.categories.ToList();
            return(View(vM));
        }
        public ActionResult Index()
        {
            ////creating roles //////

            // //IdentityRole admin = new IdentityRole("admin");
            // //IdentityRole owner = new IdentityRole("owner");
            // //IdentityRole client = new IdentityRole("client");
            // ////////creating roles roles to database by creating object of rolemanger which has function called createrole

            // //RoleManager<IdentityRole> rolemanger = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext()));

            // //rolemanger.Create(admin);
            // //rolemanger.Create(owner);
            //// rolemanger.Create(client);

            //assign roles by usermanger/////

            //UserManager<ApplicationUser> usermanger = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            //ApplicationUser admin = usermanger.FindByEmail("*****@*****.**");
            //ApplicationUser owner = usermanger.FindByEmail("*****@*****.**");
            //ApplicationUser client = usermanger.FindByEmail("*****@*****.**");

            //usermanger.AddToRole(admin.Id, "admin");
            //usermanger.AddToRole(owner.Id, "owner");
            //usermanger.AddToRole(client.Id, "client");

            if (con.categories.ToList().Count == 0)
            {
                Categories c1 = new Categories();
                Categories c2 = new Categories();
                Categories c3 = new Categories();
                Categories c4 = new Categories();
                c1.Name = "Tvs";
                c2.Name = "Mobile";
                c3.Name = "LabTops";
                c4.Name = "clother";
                con.categories.Add(c1);
                con.categories.Add(c2);
                con.categories.Add(c3);
                con.categories.Add(c4);
                con.SaveChanges();
            }

            ////////////////////////////////////////////////////
            Cat_Pro_Bra_viewModel GVM = new Cat_Pro_Bra_viewModel();

            GVM.Products   = con.products.ToList();
            GVM.Categories = con.categories.ToList();


            return(View(GVM));
        }
Esempio n. 6
0
        public ActionResult deleteCatFromBrand(int Id, int idBrand)
        {
            Brands     brand = db.brands.Find(idBrand);
            Categories cat   = db.categories.Find(Id);

            brand.cat_List.Remove(cat);
            db.SaveChanges();

            Cat_Pro_Bra_viewModel vM = new Cat_Pro_Bra_viewModel();

            vM.brand      = db.brands.Find(idBrand);
            vM.Categories = db.categories.ToList();
            vM.brand.cat_List.Where(e => e.Id == Id);
            return(RedirectToAction("Index"));
        }
        public JsonResult Create2(int id)
        {
            Cat_Pro_Bra_viewModel sss = new Cat_Pro_Bra_viewModel();
            var ll = db.categories.Find(id);
            //sss.brand.Where(e => e.catList == ll).ToList();


            string ss = JsonConvert.SerializeObject(ll.Brands.Where(e => e.approved == "Yes"),
                                                    Formatting.None,
                                                    new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Json(ss, JsonRequestBehavior.AllowGet));
        }
Esempio n. 8
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Cat_Pro_Bra_viewModel vM = new Cat_Pro_Bra_viewModel();

            vM.brand          = db.brands.Find(id);
            vM.Categories     = db.categories.ToList();
            vM.brand.cat_List = db.brands.Find(id).cat_List.ToList();
            //db.brands.Include(e => e.Name == "LG");
            if (vM.brand == null)
            {
                return(HttpNotFound());
            }
            return(View(vM));
        }
Esempio n. 9
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Cat_Pro_Bra_viewModel vM = new Cat_Pro_Bra_viewModel();

            vM.brand      = db.brands.Find(id);
            vM.Categories = vM.brand.cat_List.ToList();
            vM.Products   = vM.brand.products.ToList();
            vM.Products   = db.products.ToList();
            if (vM.brand == null)
            {
                return(HttpNotFound());
            }
            return(View(vM));
        }
Esempio n. 10
0
 public ActionResult Create(Brands brand, int?CatId)
 {
     if (ModelState.IsValid)
     {
         var catOfBrand = db.categories.Find(CatId);
         brand.approved = "Yes";
         db.brands.Add(brand);
         db.SaveChanges();
         db.brands.Find(brand.Id).cat_List.Add(catOfBrand);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         Cat_Pro_Bra_viewModel vM = new Cat_Pro_Bra_viewModel();
         vM.Categories = db.categories.ToList();
         return(View(vM));
     }
 }
 public ActionResult searching(string search)
 {
     if (!string.IsNullOrWhiteSpace(search))
     {
         if (!User.IsInRole("admin"))
         {
             Cat_Pro_Bra_viewModel GVM = new Cat_Pro_Bra_viewModel();
             GVM.Products = con.products.Where(e => (e.Descripton.Contains(search) || e.Name.Contains(search) || e.brand.Name.Contains(search) || e.cat.Name.Contains(search)) && e.Approved == "Yes").ToList();
             return(View("searching", GVM));
         }
         else
         {
             Cat_Pro_Bra_viewModel GVM = new Cat_Pro_Bra_viewModel();
             GVM.Products = con.products.Where(e => (e.Descripton.Contains(search) || e.Name.Contains(search) || e.brand.Name.Contains(search) || e.cat.Name.Contains(search))).ToList();
             return(View("searching", GVM));
         }
     }
     else
     {
         return(RedirectToAction("index"));
     }
 }
        public ActionResult Create(Products product, string NEWBRAND, HttpPostedFileBase UploadImage)
        {
            Cat_Pro_Bra_viewModel cc = new Cat_Pro_Bra_viewModel();

            cc.Categories = db.categories.ToList();
            cc.product    = product;
            if (User.IsInRole("admin"))
            {
                cc.product.Approved = "Yes";
            }
            if (NEWBRAND != "")
            {
                Brands brands = new Brands();

                brands.Name = NEWBRAND;
                if (User.IsInRole("admin"))
                {
                    brands.approved = "Yes";
                }
                db.brands.Add(brands);
                db.SaveChanges();
                var cch = db.categories.Find(product.cat_Id);
                cch.Brands.Add(brands);
                db.SaveChanges();
                product.brand_Id = brands.Id;

                product.owner_Id = User.Identity.GetUserId();


                if (UploadImage != null && product.brand_Id != null)
                {
                    ModelState.Remove("product.Imageurl");
                    ModelState.Remove("product.brand_Id");
                    UploadImage.SaveAs(Server.MapPath("/") + "/Content/" + UploadImage.FileName);
                    product.Imageurl = UploadImage.FileName;
                }
                else
                {
                    return(View(cc));
                }
                if (ModelState.IsValid)

                {
                    db.products.Add(product);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(cc));
                }
            }

            if (UploadImage != null && product.brand_Id != null)
            {
                ModelState.Remove("product.Imageurl");
                ModelState.Remove("product.brand_Id");
                product.owner_Id = User.Identity.GetUserId();
                if (UploadImage.ContentType == "image/png" || UploadImage.ContentType == "image/jpg" || UploadImage.ContentType == "image/jpeg")
                {
                    UploadImage.SaveAs(Server.MapPath("/") + "/Content/" + UploadImage.FileName);
                    product.Imageurl = UploadImage.FileName;
                }
            }


            else
            {
                return(View(cc));
            }
            if (ModelState.IsValid)
            {
                db.products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View(cc));
            }
        }