示例#1
0
        public JsonResult AddProduct(string productName, string productDescription)
        {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                HttpPostedFileBase file = Request.Files[i];

                int fileSize = file.ContentLength;
                string fileName = file.FileName;
                string mimeType = file.ContentType;
                System.IO.Stream fileContent = file.InputStream;

                string root = Server.MapPath("~/Images/Products/");
                file.SaveAs(root + fileName);

                Product product = new Product()
                {
                    Name = productName,
                    Description = productDescription,
                    ImagePath = "/Images/Products/" + fileName
                };

                ProductViewModel viewModel = Bindings.ProductToProductViewModel(product);

                AddProductResponse response = ProductService.AddProduct(new AddProductRequest { Product = product });
                if (response.Status == true)
                {
                    var context = GlobalHost.ConnectionManager.GetHubContext<VoteHub>();
                    context.Clients.All.productAdded(viewModel);
                }
            }

            return Json("Product added");
        }
示例#2
0
        public static ProductViewModel ProductToProductViewModel(Product product)
        {
            ProductViewModel prod = new ProductViewModel()
            {
                Id = product.Id,
                Name = product.Name,
                Description = product.Description,
                ImagePath = product.ImagePath,
                VotesAmount = (product.Votes != null) ? product.Votes.Count() : 0,
                ButtonClass = EnumDescription.GetEnumDescription(ButtonClass.Default),
                EditActionLink = "/Home/Edit/" + product.Id
            };

            return prod;
        }
示例#3
0
        public UpdateProductResponse EditProduct(string Id, string Name, string Description, string ImagePath)
        {
            int identity = 0;
            int.TryParse(Id, out identity);
            Product updatedProduct = new Product()
            {
                Id = identity,
                Name = Name,
                Description = Description,
                ImagePath = ImagePath
            };

            UpdateProductResponse response = ProductService.UpdateProduct(new UpdateProductRequest { Product = updatedProduct });
            return response;
        }