Ejemplo n.º 1
0
        public ActionResult Delete(int id)
        {
            var app = new ServiceReference.ContractClient();

            app.DeleteBanner(id);
            return(RedirectToAction("GetAll"));
        }
Ejemplo n.º 2
0
        public ActionResult GetAll()
        {
            var app      = new ServiceReference.ContractClient();
            var products = app.GetAllProducts();

            var model = new List <ProductViewModel>();

            foreach (var c in products)
            {
                var prod = new ProductViewModel
                {
                    Id          = c.Id,
                    Name        = c.Name,
                    Description = c.Description,
                    Enabled     = c.Enabled,
                    IsOffer     = c.IsOffer,
                    Percent     = c.Percent,
                    Price       = c.Price,
                    StartDay    = c.StartDay,
                    EndDay      = c.EndDay,
                    Warranty    = c.Warranty,
                    Brant       = c.Brant,
                    Stock       = c.Stock,
                    TypeStock   = c.TypeStock,
                };
                model.Add(prod);
            }
            return(View(model));
        }
Ejemplo n.º 3
0
        public ActionResult Add()
        {
            var app = new ServiceReference.ContractClient();

            var model         = new ProductViewModel();
            var completeModel = new ProductEditViewModel();

            completeModel.Product = model;
            var categoriesClient = app.GetAllCategories();

            completeModel.Categories = categoriesClient.Select(x => new CategoryViewModel(x)).ToList();

            foreach (var c in completeModel.Categories)
            {
                c.Children = completeModel.Categories.Where(x => x.ParentId == c.Id).ToList();
            }
            var staticList = new List <KeyValuePair <int, string> >();

            staticList.Add(new KeyValuePair <int, string>(1, "Cantidad Fija"));
            staticList.Add(new KeyValuePair <int, string>(1, "Cantidad Ilimitada"));
            staticList.Add(new KeyValuePair <int, string>(1, "Disponible en 24 hs"));


            completeModel.Inventory = staticList;
            return(View(completeModel));
        }
Ejemplo n.º 4
0
        public ActionResult GetById(int id)
        {
            var app           = new ServiceReference.ContractClient();
            var productClient = app.GetProductById(id);

            var model = new ProductViewModel(productClient);

            model.Images = app.GetImageByProductId(id);
            if (model.Images == null)
            {
                model.Images = new List <ServiceReference.Image>();
            }

            var categories = ViewBag.LayoutModel as List <CategoryViewModel>;

            model.CategoryName = categories.FirstOrDefault(x => x.Id == model.CategoryId).Name;

            model.Feature = app.GetFeatureByProductId(model.Id).Select(x => new FeatureViewModel
            {
                Id          = x.Id,
                Description = x.Description,
                Name        = x.Name
            }).ToList();

            return(View(model));
        }
Ejemplo n.º 5
0
        public BaseController()
        {
            var app        = new ServiceReference.ContractClient();
            var categories = app.GetAllCategories().Where(x => x.Enabled);

            var model = new List <CategoryViewModel>();

            foreach (var c in categories)
            {
                var cat = new CategoryViewModel
                {
                    Id       = c.Id,
                    Name     = c.Name,
                    Level    = c.Level,
                    Parent   = c.ParentId,
                    IsEnable = c.Enabled
                };
                cat.CountChildren = categories.Count(x => x.ParentId == cat.Id && x.Level == 1);
                model.Add(cat);
            }

            var imageFolder = ConfigurationManager.AppSettings["imageFolder"];

            ViewBag.imageFolder = imageFolder;
            ViewBag.LayoutModel = model;
        }
Ejemplo n.º 6
0
        public ActionResult Add()
        {
            var app = new ServiceReference.ContractClient();

            var model = new BannerViewModel();

            return(View(model));
        }
Ejemplo n.º 7
0
        public ActionResult Edit(int id)
        {
            var app           = new ServiceReference.ContractClient();
            var productClient = app.GetProductById(id);

            var model = new ProductViewModel
            {
                Id          = productClient.Id,
                Name        = productClient.Name,
                Description = productClient.Description,
                Enabled     = productClient.Enabled,
                IsOffer     = productClient.IsOffer,
                Percent     = productClient.Percent,
                Price       = productClient.Price,
                StartDay    = productClient.StartDay,
                EndDay      = productClient.EndDay,
                Warranty    = productClient.Warranty,
                Brant       = productClient.Brant,
                Images      = productClient.Image,
                CategoryId  = productClient.CategoryId,
                TypeStock   = productClient.TypeStock,
                Stock       = productClient.Stock,
            };

            model.Feature = app.GetFeatureByProductId(model.Id).Select(x => new FeatureViewModel
            {
                Id = x.Id, Description = x.Description, Name = x.Name
            }).ToList();

            model.Images = app.GetImageByProductId(id);
            if (model.Images == null)
            {
                model.Images = new List <ServiceReference.Image>();
            }
            var completeModel = new ProductEditViewModel();

            completeModel.Product = model;
            var categoriesClient = app.GetAllCategories();

            completeModel.Categories = categoriesClient.Select(x => new CategoryViewModel(x)).ToList();

            foreach (var c in completeModel.Categories)
            {
                c.Children = completeModel.Categories.Where(x => x.ParentId == c.Id).ToList();
            }

            var staticList = new List <KeyValuePair <int, string> >();

            staticList.Add(new KeyValuePair <int, string>(1, "Cantidad Fija"));
            staticList.Add(new KeyValuePair <int, string>(1, "Cantidad Ilimitada"));
            staticList.Add(new KeyValuePair <int, string>(1, "Disponible en 24 hs"));


            completeModel.Inventory = staticList;
            return(View(completeModel));
        }
Ejemplo n.º 8
0
        public ActionResult GetById(int id = 0, bool isOffer = false)
        {
            var app        = new ServiceReference.ContractClient();
            var categories = ViewBag.LayoutModel as List <CategoryViewModel>;
            List <ProductViewModel> productsToDisplay;

            if (id == 0)
            {
                if (isOffer)
                {
                    productsToDisplay = app.GetProductLastOffers(null).Select(x => new ProductViewModel(x)).ToList();
                }
                else
                {
                    productsToDisplay = app.GetAllProducts().Select(x => new ProductViewModel(x)).ToList();
                }
            }
            else
            {
                productsToDisplay = app.GetProductByCategory(id, isOffer).Select(x => new ProductViewModel(x)).ToList();
            }


            var categoriesAmount = app.GetCategoryCount(isOffer);

            foreach (var c in categories)
            {
                c.CountProduct = categoriesAmount.FirstOrDefault(x => x.Key == c.Id).Value;
            }


            foreach (var c in productsToDisplay)
            {
                c.Images = app.GetImageByProductId(c.Id);
            }
            var model = new CategoryShowViewModel
            {
                Products   = productsToDisplay,
                Categories = categories
            };

            if (id != 0)
            {
                model.CurrentCategory = categories.FirstOrDefault(x => x.Id == id);
            }


            return(View(model));
        }
Ejemplo n.º 9
0
        public ActionResult Add()
        {
            var app = new ServiceReference.ContractClient();

            var model = new CategoryViewModel();
            //obtenemso todas las categorias
            var categoriesClient = app.GetAllCategories();

            //de todas las categorias, tomamos solo las padre y por cada una generamos un categoryviewmodel
            var completeModel = categoriesClient.Where(x => x.Level == 0).Select(x => new CategoryViewModel(x)).ToList();

            model.ParentCategories = completeModel;

            return(View(model));
        }
Ejemplo n.º 10
0
        public ActionResult Edit(int id)
        {
            var app          = new ServiceReference.ContractClient();
            var BannerClient = app.GetBannerById(id);

            var model = new BannerViewModel
            {
                Id          = BannerClient.Id,
                ImageUrl    = BannerClient.ImageUrl,
                Description = BannerClient.Description,
                Title       = BannerClient.Title,
                Url         = BannerClient.Url,
            };

            return(View(model));
        }
Ejemplo n.º 11
0
 public JsonResult DeleteFile(int id)
 {
     try
     {
         var app   = new ServiceReference.ContractClient();
         var image = app.GetImageById(id);
         //Delete file from the file system
         ImageHelper.DeleteImage(image.Url);
         app.DeleteImage(id);
         return(Json(new { Result = "OK" }));
     }
     catch (Exception ex)
     {
         return(Json(new { Result = "ERROR", Message = ex.Message }));
     }
 }
Ejemplo n.º 12
0
        public ActionResult GetById(int id)
        {
            var app            = new ServiceReference.ContractClient();
            var categoryClient = app.GetCategoryById(id);
            var model          = new CategoryViewModel(categoryClient);

            //var model = new Category
            //{
            //    Id = categoryClient.Id,
            //    Name = categoryClient.Name,
            //    Description = categoryClient.Description,
            //    Level = categoryClient.Level,
            //    ParentId = categoryClient.ParentId,
            //    Enabled = categoryClient.Enabled

            //};
            return(View(model));
        }
Ejemplo n.º 13
0
        public ActionResult QuickView(int id)
        {
            var app           = new ServiceReference.ContractClient();
            var productClient = app.GetProductById(id);

            var model = new ProductViewModel(productClient);

            model.Images = app.GetImageByProductId(id);
            if (model.Images == null)
            {
                model.Images = new List <ServiceReference.Image>();
            }

            var categories = ViewBag.LayoutModel as List <CategoryViewModel>;

            model.CategoryName = categories.FirstOrDefault(x => x.Id == model.CategoryId).Name;

            return(PartialView("ViewProduct", model));
        }
Ejemplo n.º 14
0
        public ActionResult Delete(int id)
        {
            var path = Path.Combine(Server.MapPath("~/Image"), id.ToString());

            if (Directory.Exists(path))
            {
                System.IO.DirectoryInfo di = new DirectoryInfo(path);
                foreach (FileInfo file in di.GetFiles())
                {
                    file.Delete();
                }
                di.Delete(true);
            }

            var app = new ServiceReference.ContractClient();

            app.DeleteProduct(id);
            return(RedirectToAction("GetAll"));
        }
Ejemplo n.º 15
0
        public ActionResult GetAll()
        {
            var app    = new ServiceReference.ContractClient();
            var banner = app.GetAllBanner();

            var model = new List <BannerViewModel>();

            foreach (var c in banner)
            {
                var cat = new BannerViewModel
                {
                    Id          = c.Id,
                    ImageUrl    = c.ImageUrl,
                    Title       = c.Title,
                    Description = c.Description,
                    Url         = c.Url,
                };
                model.Add(cat);
            }
            return(View(model));
        }
Ejemplo n.º 16
0
        public ActionResult Edit(CategoryViewModel category)
        {
            var app = new ServiceReference.ContractClient();

            var model = new ServiceReference.Category
            {
                Id          = category.Id,
                Name        = category.Name,
                Description = category.Description,
                Level       = category.Level,
                ParentId    = category.ParentId,
                Enabled     = category.Enabled
            };

            if (category.ParentId == null)
            {
                category.ParentId = 0;
            }
            app.UpdateCategory(model);

            return(RedirectToAction("GetAll"));
        }
Ejemplo n.º 17
0
        public ActionResult Add(BannerViewModel banner)
        {
            var app  = new ServiceReference.ContractClient();
            var path = string.Empty;

            if (Request.Files.Count == 1)
            {
                path = ImageHelper.SaveImage("Banner", Request.Files[0], Server.MapPath("~/Image"));
            }
            var model = new ServiceReference.Banner
            {
                Id          = banner.Id,
                ImageUrl    = path,
                Description = banner.Description,
                Title       = banner.Title,
                Url         = banner.Url,
            };

            app.AddBanner(model);

            return(RedirectToAction("GetAll"));
        }
Ejemplo n.º 18
0
        public ActionResult Index()
        {
            var app = new ServiceReference.ContractClient();
            var lastAddedproducts = app.GetProductLastAdded(4);
            var offerproducts     = app.GetProductLastOffers(4);

            var model = new HomeViewModel();

            foreach (var c in lastAddedproducts)
            {
                var prod = new ProductViewModel(c);
                prod.Images = app.GetImageByProductId(prod.Id);
                model.LastAddedProduct.Add(prod);
            }

            foreach (var c in offerproducts)
            {
                var prod = new ProductViewModel(c);
                prod.Images = app.GetImageByProductId(prod.Id);
                model.OfferProduct.Add(prod);
            }
            var banners = app.GetAllBanner();

            foreach (var b in banners)
            {
                var ban = new BannerViewModel
                {
                    Id          = b.Id,
                    ImageUrl    = b.ImageUrl,
                    Description = b.Description,
                    Title       = b.Title,
                    Url         = b.Url,
                };
                model.BannerViewModels.Add(ban);
            }


            return(View(model));
        }
Ejemplo n.º 19
0
        public ActionResult GetAll()
        {
            var app        = new ServiceReference.ContractClient();
            var categories = app.GetAllCategories();

            var model = new List <CategoryViewModel>();

            foreach (var c in categories)
            {
                var cat = new CategoryViewModel
                {
                    Id          = c.Id,
                    Name        = c.Name,
                    Description = c.Description,
                    Enabled     = c.Enabled,
                    Level       = c.Level,
                    ParentId    = c.ParentId,
                };
                model.Add(cat);
            }

            return(View(model));
        }
Ejemplo n.º 20
0
        public ActionResult Edit(int id)
        {
            var app            = new ServiceReference.ContractClient();
            var categoryClient = app.GetCategoryById(id);

            var model = new CategoryViewModel
            {
                Id          = categoryClient.Id,
                Name        = categoryClient.Name,
                Description = categoryClient.Description,
                Level       = categoryClient.Level,
                ParentId    = categoryClient.ParentId,
                Enabled     = categoryClient.Enabled
            };
            //obtenemso todas las categorias
            var categoriesClient = app.GetAllCategories();

            //de todas las categorias, tomamos solo las padre y por cada una generamos un categoryviewmodel
            var completeModel = categoriesClient.Where(x => x.Level == 0).Select(x => new CategoryViewModel(x)).ToList();

            model.ParentCategories = completeModel;
            return(View(model));
        }
Ejemplo n.º 21
0
        public ActionResult GetById(int id)
        {
            var app           = new ServiceReference.ContractClient();
            var productClient = app.GetProductById(id);

            var model = new ProductViewModel
            {
                Id          = productClient.Id,
                Name        = productClient.Name,
                Description = productClient.Description,
                Enabled     = productClient.Enabled,
                IsOffer     = productClient.IsOffer,
                Percent     = productClient.Percent,
                Price       = productClient.Price,
                StartDay    = productClient.StartDay,
                EndDay      = productClient.EndDay,
                Warranty    = productClient.Warranty,
                Brant       = productClient.Brant,
                TypeStock   = productClient.TypeStock,
                Stock       = productClient.Stock,
            };

            return(View(model));
        }
Ejemplo n.º 22
0
        public ActionResult Add(ProductViewModel product)
        {
            var app = new ServiceReference.ContractClient();

            var model = new ServiceReference.Product
            {
                Id          = 0,
                Name        = product.Name,
                Description = product.Description,
                Enabled     = true,
                IsOffer     = product.IsOffer,
                Percent     = product.Percent,
                Price       = product.Price,
                StartDay    = product.StartDay,
                EndDay      = product.EndDay,
                CategoryId  = product.CategoryId,
                Warranty    = product.Warranty,
                Brant       = product.Brant,
                TypeStock   = product.TypeStock,
                Stock       = product.Stock,
            };

            model.Feature = product.Feature.Where(x => x.Id >= 0 && x.Name != null).Select(x => new ServiceReference.Feature
            {
                Description = x.Description,
                Name        = x.Name,
                Id          = x.Id,
                ProductID   = model.Id
            }).ToList();
            model.Image = new List <ServiceReference.Image>();

            var id = app.AddProduct(model);


            for (int i = 0; i < Request.Files.Count; i++)
            {
                var file = Request.Files[i];
                if (file.FileName == string.Empty)
                {
                    continue;
                }
                var path = ImageHelper.SaveImage(id.ToString(), file, Server.MapPath("~/Image"));


                bool isMain = false;
                if (Request.Files.AllKeys[i] == "file")
                {
                    isMain = true;
                }
                var imagetosave = new ServiceReference.Image
                {
                    Url       = path,
                    IsMain    = isMain,
                    ProductId = id
                };
                model.Image.Add(imagetosave);
            }
            app.AddImageRange(model.Image);


            return(RedirectToAction("GetAll"));
        }