Example #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));
        }
Example #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));
        }