Exemplo n.º 1
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));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
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));
        }