예제 #1
0
        //
        // GET: /Order/
        public virtual ActionResult Form(string id)
        {
            var model = new FormViewModel(ViewData.Model as BaseViewModel);
            var product1 = new ProductViewModel
                               {
                                   Title = "Karrbros Official Shirt",
                                   Price = 19.99,
                                   MaxOrderQuantity = 10,
                                   DescriptionLine1 = "50/50  Cotton Jerzee",
                                   DescriptionLine2 = "White Shirt - Blue/Orange Ink",
                                   AvailableSizes = new List<string> {"Small", "Medium", "Large", "X-Large"}
                               };
            var images = new List<ImageViewModel>();
            var image = new ImageViewModel
                            {
                                AltText = "Karrbros Official Shirt",
                                Path =string.Format("{0}/{1}/officialshirt.png", model.URLs.CDNOrders, id),
                                Title = "Karrbros Official Shirt"
                            };
            images.Add(image);
            product1.Images = images;
            model.Order.Products.Add(product1);
            model.Order.Title = "Karrbros Official";
            var crumb = new BreadCrumbViewModel { Display = "Order Search", Title = "order search", Url = "/Order/Search" };
            var crumb2 = new BreadCrumbViewModel { Display = model.Order.Title, Title = model.Order.Title, Url = "/Order/Form/" + model.Order.Id };
            model.BreadCrumbs.Add(crumb);
            model.BreadCrumbs.Add(crumb2);

               return View("Form", model);
        }
        //
        // GET: /Store/
        public ActionResult Index()
        {
            ProductApplicationService productApplicationService = new ProductApplicationService();

            ProductViewModel productViewModel = new ProductViewModel();
            productViewModel.Products = productApplicationService.GetProducts().Products;
            return View("Index", productViewModel);
        }
예제 #3
0
        protected ProductViewModel DisplayDetails(ProductViewModel vmChanged)
        {
            var vm = new ProductViewModel();
            vm.DisplayName = Strings.ProductViewModel_DisplayName;
            vm.Model = vmChanged.Model;

            return vm;
        }
        public ActionResult Browse(string category)
        {
            ProductApplicationService productApplicationService = new ProductApplicationService();
            ProductViewModel productViewModel2 = new ProductViewModel();
            // Retrieve Category and its Associated Products from database

            productViewModel2.Products = productApplicationService.GetCategoryProducts(category).Products;
            return View("Index", productViewModel2);
        }
예제 #5
0
 public virtual ActionResult Create(ProductViewModel model)
 {
     if (ModelState.IsValid)
     {
         _productHandler.Add(model.CreateProductDomain());
         _productHandler.Commit();
         return RedirectToAction("Index");
     }
     return View(model);
 }
        public ActionResult Edit(ProductViewModel productViewModel)
        {
            if (ModelState.IsValid)
            {
                _productAppService.Update(productViewModel);
                return RedirectToAction("Index");
            }

            return View(productViewModel);
        }
        public ActionResult Update([DataSourceRequest]DataSourceRequest request, ProductViewModel model)
        {
            if (model != null && ModelState.IsValid)
            {
                var user = this.Mapper.Map<Product>(model);

                this.products.Update(user);
            }
            return Json(new[] { model }.ToDataSourceResult(request, ModelState));
        }
        public ActionResult Create(ProductViewModel model)
        {
            if (ModelState.IsValid)
            {
                var productDb = this.Mapper.Map<Product>(model);
                this.products.Add(productDb);
                this.products.SaveChanges();
            }

            return RedirectToAction("Index");
        }
        public ActionResult Delete([DataSourceRequest]DataSourceRequest request, ProductViewModel model)
        {
            if (model != null)
            {
                this.products.Delete(model.Id);

                return this.Json(new[] { model }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
            }

            return null;
        }
예제 #10
0
 public ActionResult Delete(int id, ProductViewModel model)
 {
     try
     {
         _productService.Delete(id);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
 public async Task<ActionResult> GetProduct(int id)
 {
     var product = await productClient.GetProduct(id);
     var model = new ProductViewModel
     {
         ProductId = product.Data.ProductId,
         Name = product.Data.Name,
         Description = product.Data.Description,
         CreatedOn = product.Data.CreatedOn.ToLongDateString() + " " + product.Data.CreatedOn.ToLongTimeString()
     };
     return View(model);
 }
        public async Task<ActionResult> CreateProduct(ProductViewModel model)
        {
            var response = await productClient.CreateProduct(model);
            if (response.StatusIsSuccessful)
            {
                var productId = response.Data;
                return RedirectToAction("GetProduct", new { id = productId });
            }

            AddResponseErrorsToModelState(response);
            return View(model);
        }
예제 #13
0
        public ActionResult Create(ProductViewModel model)
        {
            if (ModelState.IsValid)
            {
                var product = Mapper.Map(model, new Product());

                if (model.StoreId != 0)
                {
                    _productService.CreateForStore(product, model.StoreId);
                    return RedirectToAction("Details", "Store", new { id = model.StoreId });
                }
                else
                {
                    _productService.Create(product);
                    return RedirectToAction("Index");
                }
            }
            else
            {
                return View();
            }
        }
예제 #14
0
        public ActionResult Create(ProductViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return this.View(model);
            }

            var newProduct = this.Mapper.Map<Product>(model);

            if (model.Picture != null && model.Picture.ContentLength > 0)
            {
                newProduct.PictureName = Helpers.CreateUniqueFileName(model.Picture.FileName) + "." + Helpers.GetFileTypeFromName(model.Picture.FileName).ConvertToPictureType();

                // store the product picture inside ~/Content/Images/Products folder
                var path = Path.Combine(Server.MapPath(GlobalConstants.ProductsImagesPath), newProduct.PictureName);
                model.Picture.SaveAs(path);
            }

            products.Add(newProduct);
            products.Save();

            return RedirectToAction("Index");
        }
예제 #15
0
        public ActionResult Products_Create([DataSourceRequest]DataSourceRequest request, ProductViewModel product)
        {
            this.TempData["Categories"] = this.Cache.Get(
                    "categories",
                    () => this.Categories.GetAll()
                                        .Select(c => new SelectListItem { Value = c.Id.ToString(), Text = c.Name })
                                        .ToList(),
                    30 * 60);

            var newId = 0;
            if (this.ModelState.IsValid)
            {
                var entity = new Product
                {
                    Name = product.Name,
                    Sku = product.Sku,
                    Barcode = product.Barcode,
                    HeigthInCm = product.HeigthInCm,
                    WidthInCm = product.WidthInCm,
                    WeightInGr = product.WeightInGr,
                    DeliveryUnit = product.DeliveryUnit,
                    MinDayOfExpiryInDays = product.MinDayOfExpiryInDays,
                    IsBlocked = product.IsBlocked,
                    SupplierId = this.UserProfile.Organization.Id
                };

                this.Products.Add(entity);
                product.Id = entity.Id;
            }

            var productsToDisplay = this.Products.All()
                .Project()
                .To<ProductViewModel>()
                .FirstOrDefault(x => x.Id == newId);

            return this.Json(new[] { productsToDisplay }.ToDataSourceResult(request, this.ModelState));
        }
예제 #16
0
        public ActionResult Edit(int id, ProductViewModel model)
        {
            if (ModelState.IsValid)
            {
                var product = _productService.GetById(id);
                Mapper.Map(model, product);
                _productService.Update(product);

                return RedirectToAction("Index");
            }
            else
            {
                return View();
            }
        }
예제 #17
0
 // GET: Product/Create
 public ActionResult Create(int parentId = 0)
 {
     var model = new ProductViewModel { StoreId = parentId };
     return View(model);
 }
예제 #18
0
        protected ActionResult StoreEntity(ProductViewModel vm)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Service.StoreProduct(vm.Model);

                    // Finish Action and go back to Index
                    StoreViewModelToTempData(vm);
                    return RedirectToAction("Index");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Error", ex);
            }

            // Finish Action without saving
            StoreViewModelToTempData(vm);
            return View(vm);
        }
예제 #19
0
 public ActionResult Edit(ProductViewModel vmChanged)
 {
     ProductViewModel vm = DisplayDetails(vmChanged);
     return StoreEntity(vm);
 }
 public ActionResult CreateProduct()
 {
     var model = new ProductViewModel();
     return View(model);
 }
예제 #21
0
 public virtual ActionResult Delete(ProductViewModel model)
 {
     _productHandler.Delete(model.Id);
     _productHandler.Commit();
     return RedirectToAction("Index");
 }
예제 #22
0
        private static void SetDropDownListsProperties(ProductViewModel product)
        {
            if (product.PCSQuantities != null && product.PCSQuantities.Count() > 0)
            {
                IEnumerable<IGrouping<ColorViewModel, PCSQuantitiesViewModel>> productColorGroups
                    = product.PCSQuantities.GroupBy(p => p.Color);

                IGrouping<ColorViewModel, PCSQuantitiesViewModel> firstProductColorGroup = productColorGroups.FirstOrDefault();

                PCSQuantitiesViewModel firstPCSQuantity = firstProductColorGroup.First(); ;

                if (productColorGroups.Count() == 1 && firstProductColorGroup.Key == null)
                {
                    product.SelectedPCSQuantityID = firstProductColorGroup.Select(x => x.ID).FirstOrDefault();
                }
                else
                {
                    product.ProductColors = new List<SelectListItem>();
                    int counter = 1;
                    foreach (var group in productColorGroups)
                    {
                        product.ProductColors
                            .Add(new SelectListItem { Value = group.Key.HexCode, Text = group.Key.Name, Selected = counter == 1 });
                        counter++;
                    }

                    product.ProductSizes = firstProductColorGroup
                        .Select(p => new SelectListItem { Value = p.Size.ID.ToString(), Text = p.Size.Name }).ToList();
                    product.ProductSizes.FirstOrDefault().Selected = true;
                }

                product.ProductQuantities = GetProductQuantities(firstPCSQuantity.Quantity);
                product.SelectedPCSQuantityID = firstPCSQuantity.ID;
            }
        }
예제 #23
0
 public virtual ActionResult Create()
 {
     ProductViewModel model = new ProductViewModel();
     model.AllCustomers = _customerHandler.GetAll().Select(CustomerViewModelFactory.Create);
     return View(model);
 }
예제 #24
0
        /// <summary>
        /// Creates a product view model based on an Item and Rendering
        /// </summary>
        /// <param name="productItem">The product item to based the model on</param>
        /// <param name="rendering">The rendering to initialize the model with</param>
        /// <returns>A Product View Model</returns>
        protected ProductViewModel GetProductViewModel(Item productItem, Rendering rendering)
        {
            if (this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] != null)
            {
                return (ProductViewModel) this.CurrentSiteContext.Items[CurrentProductViewModelKeyName];
            }

            var variants = new List<VariantViewModel>();
            if (productItem != null && productItem.HasChildren)
            {
                foreach (Item item in productItem.Children)
                {
                    var v = new VariantViewModel(item);
                    variants.Add(v);
                }
            }

            var productViewModel = new ProductViewModel();
            productViewModel.Initialize(rendering, variants);
            PopulateStockInformation(productViewModel);

            this.CurrentSiteContext.Items[CurrentProductViewModelKeyName] = productViewModel;

            return (ProductViewModel)this.CurrentSiteContext.Items[CurrentProductViewModelKeyName];
        }
예제 #25
0
        public ActionResult Products_Update([DataSourceRequest]DataSourceRequest request, ProductViewModel product)
        {
            this.TempData["Categories"] = this.Cache.Get(
                    "categories",
                    () => this.Categories.GetAll()
                                        .Select(c => new SelectListItem { Value = c.Id.ToString(), Text = c.Name })
                                        .ToList(),
                    30 * 60);

            if (this.ModelState.IsValid)
            {
                this.Products.Update(Mapper.Map<Product>(product));
            }

            var postToDisplay = this.Products.All().Project()
                           .To<ProductViewModel>()
                           .FirstOrDefault(x => x.Id == product.Id);
            return this.Json(new[] { postToDisplay }.ToDataSourceResult(request, this.ModelState));
        }
예제 #26
0
        public ActionResult Products_Destroy([DataSourceRequest]DataSourceRequest request, ProductViewModel product)
        {
            this.Products.Delete(Mapper.Map<Product>(product));

            return this.Json(new[] { product }.ToDataSourceResult(request, this.ModelState));
        }
예제 #27
0
        public ActionResult Update(ProductViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return this.View();
            }

            var productForUpdate = this.products.GetById(model.Id);

            productForUpdate.CategoryId = model.CategoryId;
            productForUpdate.Name = model.Name;
            productForUpdate.Measure = model.Measure;
            productForUpdate.Amount = model.Amount;
            productForUpdate.Price = model.Price;
            productForUpdate.NewPrice = model.NewPrice;

            if(model.Picture != null && model.Picture.ContentLength > 0 && model.Picture.FileName != GlobalConstants.DefaultNoPictureName)
                // there is new picture
            {
                string path;
                if (productForUpdate.PictureName != GlobalConstants.DefaultNoPictureName)
                    // there is old picture
                {
                    // delete old picture
                    path = Path.Combine(Server.MapPath(GlobalConstants.ProductsImagesPath), productForUpdate.PictureName);
                    if ((System.IO.File.Exists(path)))
                    {
                        System.IO.File.Delete(path);
                    }
                }

                // and save new picture
                productForUpdate.PictureName = Helpers.CreateUniqueFileName(model.Picture.FileName) + "." + Helpers.GetFileTypeFromName(model.Picture.FileName).ConvertToPictureType();

                // store the product picture inside ~/Content/Images/Products folder
                path = Path.Combine(Server.MapPath(GlobalConstants.ProductsImagesPath), productForUpdate.PictureName);
                model.Picture.SaveAs(path);
            }

            productForUpdate.InStock = model.InStock;

            products.Update(productForUpdate);
            products.Save();

            return RedirectToAction("Index");
        }
예제 #28
0
        /// <summary>
        /// Populates the stock information
        /// </summary>
        /// <param name="model">The product model</param>
        protected void PopulateStockInformation(ProductViewModel model)
        {
            var stockInfos = this.InventoryManager.GetStockInformation(this.CurrentStorefront, new List<CommerceInventoryProduct> { new CommerceInventoryProduct { ProductId = model.ProductId, CatalogName = model.CatalogName } }, StockDetailsLevel.Status).Result;
            var stockInfo = stockInfos.FirstOrDefault();
            if (stockInfo == null || stockInfo.Status == null)
            {
                return;
            }

            model.StockStatus = stockInfo.Status;
            this.InventoryManager.VisitedProductStockStatus(this.CurrentStorefront, stockInfo, string.Empty);
        }
예제 #29
0
        private ProductViewModel Get(int productId)
        {
            var linq = _productRepository.Get(v => v.Id == productId);

            var s = linq.Join(_storeRepository.Get(v => v.Status.Equals((int)DataStatus.Normal)), f => f.Store_Id,
                         p => p.Id, (f, p) => new
                         {
                             P = f,
                             S = p
                         }).FirstOrDefault();
            var b =
                linq.Join(_brandRepository.Get(v => v.Status.Equals((int)DataStatus.Normal)), f => f.Brand_Id,
                          p => p.Id, (f, p) =>
                                     new
                                         {
                                             B = p,
                                             P = f
                                         }).FirstOrDefault();
            var t = linq.Join(_tagRepository.Get(v => v.Status.Equals((int)DataStatus.Normal)), f => f.Tag_Id,
                          p => p.Id, (f, p) =>
                                     new
                                     {
                                         T = p,
                                         P = f
                                     }).FirstOrDefault();

            var prod = linq.FirstOrDefault();

            if (prod == null)
            {
                return null;
            }

            var result = new ProductViewModel
                {
                    Brand = b == null ? null : b.B,
                    Product = prod,
                    Store = s == null ? null : s.S,
                    Tag = t == null ? null : t.T
                };

            return result;
        }
 public ActionResult Aa()
 {
     ProductViewModel a = new ProductViewModel() {name = "ikebana", cijena = "beton"};
     return View(a);
 }