Ejemplo n.º 1
0
        public ActionResult EditProduct(string seller, string name = "", string description = "")
        {
            List <int> lSeller = seller.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(Int32.Parse).ToList();

            name        = name.ToLower();
            description = description.ToLower();
            List <Product> model = new List <Product>();

            using (ManaCenaEntities context = new ManaCenaEntities())
            {
                model = context.Products
                        .Include(o => o.Cathegory.CathegoryType)
                        .Include(o => o.SubCathegory.Cathegory.CathegoryType)
                        .Include(o => o.ProductImage)
                        .Include(o => o.ProductImageSmall)
                        .Include(o => o.ProductLocations)
                        .Where(o =>
                               (lSeller.Contains(o.Seller.Id))
                               //seller == "" || o.Seller == null || o.Seller.Name.ToLower().Contains(seller))
                               && (name == "" || o.Name.ToLower().Contains(name)) &&
                               (description == "" || o.Description.ToLower().Contains(description))
                               )
                        .ToList();

                ViewBag.SubCathegoryEnum  = context.SubCathegories.ToList();
                ViewBag.CathegoryEnum     = context.Cathegories.ToList();
                ViewBag.CathegoryTypeEnum = context.CathegoryTypes.ToList();
                ViewBag.SellerEnum        = context.Sellers.Include(o => o.Locations).ToList();
            }

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Search(List <int> sellersList, string search = "", Nullable <int> subCathegoryId = null, Nullable <int> cathegoryId = null, Nullable <int> cathegoryTypeId = null)
        {
            List <Product> model = new List <Product>();

            if (sellersList == null)
            {
                sellersList = new List <int>();
            }

            using (ManaCenaEntities context = new ManaCenaEntities())
            {
                model = context.Products
                        //.Include(o => o.ProductImage)
                        .Include(o => o.ProductImageSmall)
                        .Include(o => o.Seller)
                        .Include(o => o.Seller.SellerImage)
                        .Where(o =>
                               (o.SubCathegoryId == subCathegoryId || subCathegoryId == null) &&
                               (o.CathegoryId == cathegoryId || cathegoryId == null) &&
                               (o.CathegoryTypeId == cathegoryTypeId || cathegoryTypeId == null) &&
                               (sellersList.Count == 0 || sellersList.Contains(o.SellerId))
                               ).ToList();
            }

            return(PartialView("ProductDashboard", model));
        }
Ejemplo n.º 3
0
 public bool EditSeller(Seller rec)
 {
     using (ManaCenaEntities context = new ManaCenaEntities())
     {
         context.Sellers.Add(rec);
         if (rec.Id > 0)
         {
             context.Entry(rec).State = System.Data.Entity.EntityState.Modified;
             if (rec.SellerImage != null)
             {
                 if (rec.SellerImage.Id > 0)
                 {
                     context.Entry(rec.SellerImage).State = System.Data.Entity.EntityState.Modified;
                 }
                 else
                 {
                     context.Entry(rec.SellerImage).State = System.Data.Entity.EntityState.Added;
                 }
             }
         }
         else
         {
             context.Entry(rec).State             = System.Data.Entity.EntityState.Added;
             context.Entry(rec.SellerImage).State = System.Data.Entity.EntityState.Added;
             rec.SellerImage.Id = 0;
         }
         context.SaveChanges();
     }
     return(true);
 }
Ejemplo n.º 4
0
 public string GetLargeImage(int id)
 {
     using (ManaCenaEntities context = new ManaCenaEntities())
     {
         var img = context.ProductImages.Where(o => o.Id == id).Select(o => o.Image).First();
         return(img);
     }
 }
Ejemplo n.º 5
0
 // GET: Product
 public ActionResult Index()
 {
     using (ManaCenaEntities context = new ManaCenaEntities())
     {
         ViewBag.SellerEnum = context.Sellers.ToList();
     }
     return(View());
 }
Ejemplo n.º 6
0
        public ActionResult Index()
        {
            TestModel model = new TestModel();

            using (ManaCenaEntities context = new ManaCenaEntities())
            {
                model.p = context.Products.FirstOrDefault();
            }
            return(View(model));
        }
Ejemplo n.º 7
0
        public ActionResult EditCathegoryType()
        {
            List <CathegoryType> model = new List <CathegoryType>();

            using (ManaCenaEntities context = new ManaCenaEntities())
            {
                model = context.CathegoryTypes.ToList();
            }
            return(View(model));
        }
Ejemplo n.º 8
0
        public ActionResult EditLocation()
        {
            List <Location> model = new List <Location>();

            using (ManaCenaEntities context = new ManaCenaEntities())
            {
                model = context.Locations.ToList();
                ViewBag.SellerEnum = context.Sellers.ToList();
            }
            return(View(model));
        }
Ejemplo n.º 9
0
        public ActionResult EditSubCathegory()
        {
            List <SubCathegory> model = new List <SubCathegory>();

            using (ManaCenaEntities context = new ManaCenaEntities())
            {
                model = context.SubCathegories.ToList();
                ViewBag.CathegoryEnum = context.Cathegories.ToList();
            }
            return(View(model));
        }
Ejemplo n.º 10
0
        public ActionResult EditSeller()
        {
            List <Seller> model = new List <Seller>();

            using (ManaCenaEntities context = new ManaCenaEntities())
            {
                model = context.Sellers
                        .Include(o => o.SellerImage)
                        .ToList();
            }
            return(View(model));
        }
Ejemplo n.º 11
0
 public bool DeleteItem(int id)
 {
     using (ManaCenaEntities context = new ManaCenaEntities())
     {
         var rec = new Product {
             Id = id
         };
         context.Entry(rec).State = System.Data.Entity.EntityState.Deleted;
         context.SaveChanges();
     }
     return(true);
 }
Ejemplo n.º 12
0
 public string GetImageSmall(int id)
 {
     using (ManaCenaEntities context = new ManaCenaEntities())
     {
         var rec = context.Products.Include(o => o.ProductImageSmall).Where(o => o.Id == id).FirstOrDefault();
         if (rec.ProductImageSmall != null && !string.IsNullOrEmpty(rec.ProductImageSmall.Image))
         {
             return(rec.ProductImageSmall.Image);
         }
         else
         {
             return("");
         }
     }
 }
Ejemplo n.º 13
0
 public bool EditLocation(Location rec)
 {
     using (ManaCenaEntities context = new ManaCenaEntities())
     {
         context.Locations.Add(rec);
         if (rec.Id > 0)
         {
             context.Entry(rec).State = System.Data.Entity.EntityState.Modified;
         }
         else
         {
             context.Entry(rec).State = System.Data.Entity.EntityState.Added;
         }
         context.SaveChanges();
     }
     return(true);
 }
Ejemplo n.º 14
0
 public bool EditCathegoryType(CathegoryType rec)
 {
     using (ManaCenaEntities context = new ManaCenaEntities())
     {
         context.CathegoryTypes.Add(rec);
         if (rec.Id > 0)
         {
             context.Entry(rec).State = System.Data.Entity.EntityState.Modified;
         }
         else
         {
             context.Entry(rec).State = System.Data.Entity.EntityState.Added;
         }
         context.SaveChanges();
     }
     return(true);
 }
Ejemplo n.º 15
0
        public ActionResult ProductView(int id)
        {
            Product model = null;

            using (ManaCenaEntities context = new ManaCenaEntities())
            {
                model = context.Products
                        .Include(o => o.Cathegory.CathegoryType)
                        .Include(o => o.SubCathegory.Cathegory.CathegoryType)
                        .Include(o => o.ProductImage)
                        //.Include(o => o.ProductImageSmall)
                        .Include(o => o.ProductLocations)
                        .Include(o => o.Seller)
                        .Include(o => o.Seller.SellerImage)
                        .Where(o => o.Id == id)
                        .First();
            }

            return(PartialView(model));
            //return View(model);
        }
Ejemplo n.º 16
0
        public ActionResult Index()
        {
            List <Product> model = new List <Product>();

            using (ManaCenaEntities context = new ManaCenaEntities())
            {
                //ViewBag.CathegoryTypeEnum = context
                //    .CathegoryTypes
                //    .Include(o => o.Cathegories.Select(q => q.SubCathegories)).ToList()
                //    .ToList();

                var menuList = context
                               .CathegoryTypes
                               .Include(o => o.Cathegories.Select(k => k.SubCathegories))
                               .OrderBy(o => o.Name)
                               .ToList();

                // lame order by, EF cna't hande a shit
                foreach (var team in menuList)
                {
                    team.Cathegories = team.Cathegories.OrderBy(m => m.Name).ToList();
                    foreach (var teamMember in team.Cathegories)
                    {
                        teamMember.SubCathegories = teamMember.SubCathegories.OrderBy(u => u.Name).ToList();
                    }
                }

                ViewBag.CathegoryTypeEnum = menuList;

                ViewBag.CathegoryEnum    = context.Cathegories.ToList();
                ViewBag.SubCathegoryEnum = context.SubCathegories.ToList();

                ViewBag.SellerEnum = context.Sellers.ToList();

                //ViewBag.CathegoryEnum = context.Cathegories.Include(o => o.CathegoryType).OrderBy(o => o.CathegoryType.Name).ToList();
            }

            return(View());
        }
Ejemplo n.º 17
0
        public bool EditItem(Product rec)
        {
            //ProductLocation peredajotsa, sledujushije shagi:
            //1) Proverj ne perezapisivajutsa li oni
            //2) Proverj, chtobi stiralis vse predidushije esli v nachale bili XX/X/XXX a potm pusto
            //2.1.) Sohranenije novoj zapisi
            //3) Otobrazhenije
            // 4) otobrazhenije v Detailes

            using (ManaCenaEntities context = new ManaCenaEntities())
            {
                //dell all Locations (if any)
                context.ProductLocations.RemoveRange(context.ProductLocations.Where(o => o.ProductId == rec.Id));

                if (rec.ProductLocations.Count == context.Locations.Count(o => o.SellerId == rec.SellerId))
                {
                    rec.ProductLocations = null;
                }

                context.Products.Add(rec);
                if (rec.Id > 0)
                {
                    context.Entry(rec).State = System.Data.Entity.EntityState.Modified;
                    if (rec.ProductImage != null)
                    {
                        context.Entry(rec.ProductImage).State = System.Data.Entity.EntityState.Modified;
                    }
                    if (rec.ProductImageSmall != null)
                    {
                        context.Entry(rec.ProductImageSmall).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        rec.ProductImageSmall = new ProductImageSmall();
                    }

                    rec.ProductImageSmall.Image = Helpers.ImageHelper.ResizeImage(rec.ProductImage.Image);

                    //// if same image in DB already, do not overwrite then
                    //var image = context.ProductImages.Where(o => o.Id == rec.ProductImageId).First();
                    //if (rec.ProductImage != null && image != null && image.Image != rec.ProductImage.Image)
                    //{
                    //    rec.ProductImageSmall = new ProductImageSmall { Image = Helpers.ImageHelper.ResizeImage(rec.ProductImage.Image) };
                    //}
                }
                else
                {
                    context.Entry(rec).State = System.Data.Entity.EntityState.Added;
                    context.Entry(rec.ProductImage).State = System.Data.Entity.EntityState.Added;
                    rec.ProductImage.Id   = 0;
                    rec.ProductImageSmall = new ProductImageSmall {
                        Image = Helpers.ImageHelper.ResizeImage(rec.ProductImage.Image)
                    };
                }



                context.SaveChanges();
            }
            return(true);
        }