Exemplo n.º 1
0
 public CreateProductModelResult(CreateProductModel createProductModel)
 {
     IsInStock = createProductModel.IsInStock;
     Name      = createProductModel.Name;
     Sku       = createProductModel.Sku;
     StoreId   = createProductModel.StoreId;
 }
Exemplo n.º 2
0
        public IActionResult Create(CreateProductModel model)
        {
            if (!this.IsValidModel(model))
            {
                return(this.View());
            }

            int  productId;
            bool result = int.TryParse(model.ProductType, out productId);

            if (!result)
            {
                return(this.View());
            }

            var product = new Product
            {
                Name        = model.Name,
                Price       = model.Price,
                Description = model.Description
            };

            using (this.Context)
            {
                product.ProductType = this.Context
                                      .ProductTypes
                                      .Where(p => p.Id == productId)
                                      .Select(p => p)
                                      .FirstOrDefault();

                this.Context.Products.Add(product);
                this.Context.SaveChanges();
            }
            return(this.RedirectToHome());
        }
Exemplo n.º 3
0
        public ActionResult Create(CreateProductModel productModel)
        {
            if (this.ModelState.IsValid)
            {
                var authorId = this.User.Identity.GetUserId();

                var product = new Product
                {
                    Name        = productModel.Name,
                    Categorie   = productModel.Categorie,
                    Description = productModel.Description,
                    Price       = productModel.Price,
                    ImageUrl    = productModel.ImageUrl,
                    AuthorId    = authorId,
                };

                var db = new StoreDbContext();

                db.Products.Add(product);
                db.SaveChanges();

                return(RedirectToAction("Details", new { id = product.Id }));
            }

            return(View(productModel));
        }
        public IHttpActionResult CreateProduct([FromBody] CreateProductModel model)
        {
            var id            = AggregateId.NewAggregateId(Guid.NewGuid());
            var versionNumber = AggregateVersion.NewExpected(0);
            var cmd           = Command.NewCreate(model.Name, model.Price);
            var envelope      = createCommand(id, versionNumber, null, null, null, cmd);

            QueueCommand(envelope);

            if (model.Quantity > 0)
            {
                cmd      = Command.NewAddToStock(model.Quantity);
                envelope = createCommand(id, AggregateVersion.Irrelevant, null, null, null, cmd);
                QueueCommand(envelope);
            }

            return(Ok(new ProductModel
            {
                Id = id.Item,
                Name = model.Name,
                Price = model.Price,
                Quantity = model.Quantity,
                Reserved = 0
            }));
        }
Exemplo n.º 5
0
        //
        // GET: /Admin/Product/Create

        public ActionResult Create()
        {
            var model = new CreateProductModel();

            model.AllCategories = _productCategoryService.GetProductCategorySelectList(model.CategoryName, GlobalHelper.SelectListDefaultOption);
            return(View(model));
        }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "Name,Description,ColorId,CategoryId,Price, Image")]  CreateProductModel model, HttpPostedFileBase file)
        {
            string imagePath = Directory.GetParent(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath).Parent.FullName + @"\BlombukettenOnline\Content\images";

            if (file != null && file.ContentLength > 0)
            {
                var fileName = Path.GetFileName(file.FileName);

                var path = Path.Combine(imagePath, fileName);
                file.SaveAs(path);

                var pathTwo = Path.Combine(Server.MapPath("~/Images"), fileName);
                file.SaveAs(pathTwo);

                model.Image = fileName;
            }

            if (model.Image == null)
            {
                model.Image = "BildSaknas.jpg";
            }

            if (ModelState.IsValid)
            {
                Post(model);

                return(RedirectToAction("Index"));
            }
            Create();

            return(View());
        }
Exemplo n.º 7
0
        public async Task <int> CreateProductAsync(CreateProductModel model)
        {
            var idTokens = model.CategoryAndSubcategoryId
                           .Split(":", StringSplitOptions.RemoveEmptyEntries)
                           .Select(int.Parse)
                           .ToArray();
            var categoryId    = idTokens[0];
            int?subcategoryId = null;

            if (idTokens.Length == 2)
            {
                subcategoryId = idTokens[1];
            }

            var price   = decimal.Parse(model.Price, CultureInfo.InvariantCulture);
            var product = new Product
            {
                Name          = model.Name,
                Price         = price,
                Quantity      = model.Quantity,
                Description   = model.Description,
                ImageUrl      = model.ImageUrl,
                CategoryId    = categoryId,
                SubcategoryId = subcategoryId,
                UserId        = model.UserId,
            };

            await this.repository.AddAsync(product);

            await this.repository.SaveChangesAsync();

            return(product.Id);
        }
Exemplo n.º 8
0
        public IHttpActionResult Create(CreateProductModel model)
        {
            IHttpActionResult httpActionResult;

            if (string.IsNullOrEmpty(model.Name))
            {
                error.Add("Name is required");
            }
            if (error.errors.Count == 0)
            {
                Product product = new Product();
                product.ProductCode    = "SP" + RemoveSpacesAndSpecialCharacters.convertToUnSign(model.Name).ToUpper();
                product.Name           = model.Name;
                product.Price          = model.Price;
                product.PromotionPrice = model.PromotionPrice;
                product.CreatedDate    = DateTime.Now;
                product.CreatedBy      = User.Identity.Name;

                product = db.Products.Add(product);
                db.SaveChanges();
                httpActionResult = Ok(new ProductModel(product));
            }
            else
            {
                httpActionResult = new ErrorActionResult(Request, HttpStatusCode.BadRequest, error);
            }
            return(httpActionResult);
        }
Exemplo n.º 9
0
        public ActionResult Edit(CreateProductModel model, int?id)
        {
            Product product = setzDB.Products.Find(id);

            product.Name    = model.name;
            product.Price   = model.price ?? 0;
            product.Articul = model.articul;
            product.About   = model.about;

            product.Discount    = model.discount;
            product.MinQuantity = model.quantity;

            product.SectionID     = model.sectionID;
            product.SubSectionID  = model.subSectionID;
            product.CategoryID    = model.categoryID;
            product.SubCategoryID = model.subCategoryID;
            product.BrandID       = model.brandID;

            if (model.File != null)
            {
                string fileName = "product" + product.ID.ToString() + ".jpg";
                product.Image = fileName;
                var path = Path.Combine(System.Web.HttpContext.Current.Server.MapPath("~/Images/Product/"), fileName);
                model.File.SaveAs(path);
            }
            setzDB.SaveChanges();

            updateColros(product.ID, model.colors);
            updateSizes(product.ID, model.sizes);

            return(RedirectToAction("Detail", "Product", new { id = product.ID }));
        }
Exemplo n.º 10
0
        public HttpResponseMessage SaveProduct(CreateProductModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(System.Net.HttpStatusCode.BadRequest, ModelState));
            }

            ImageManager saver = ImageManager.GetSaverInstance();

            string imagePath = saver.SaveImage(model.Image);

            Product product = new Product {
                Name      = model.Name,
                Price     = model.Price,
                SellPrice = model.SellPrice,
                TypeId    = model.TypeId,
                Image     = new EoraMarketplace.Data.Domain.Images.Picture {
                    IsAvatar = false,
                    ImageUrl = ImageManager.ToVirtualPath(imagePath)
                },
            };

            _goodsService.CreateProduct(product, model.Classes, model.Stats);

            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
        }
        public IActionResult CreateProduct(IFormCollection valueCollection)
        {
            string code        = valueCollection["i_code"];
            string name        = valueCollection["i_name"];
            string description = valueCollection["i_description"];
            string priceStr    = valueCollection["i_price"];

            try
            {
                decimal price          = 0;
                bool    priceToDecimal = Decimal.TryParse(priceStr, out price);

                ProductManagement  pm    = new ProductManagement();
                CreateProductModel model = new CreateProductModel()
                {
                    Code        = code,
                    Name        = name,
                    Description = description,
                    Price       = price
                };
                CreateProductResultModel result = pm.Create(model);
            }
            catch (Exception ex)
            {
                return(new ContentResult()
                {
                    Content = "An error has occurred: " + Environment.NewLine + ex.Message
                });
            }

            return(RedirectToAction("Search"));
        }
Exemplo n.º 12
0
        public ActionResult Create(CreateProductModel vm)
        {
            try
            {
                //Keep the list of DropDown
                vm.CategoryList = _categoryService.List().OrderBy(x => x.Name).ToList();

                //Check data validation
                if (!ModelState.IsValid)
                {
                    this.AddToastMessage(Messages.InvalidValueField, ToastType.Error);
                    return(View("Create", vm));
                }

                //Create Product
                _productService.Create(vm);

                //Successfully message
                this.AddToastMessage(string.Format(Messages.RecordSavedSuccessfully, "product"), ToastType.Success);

                return(RedirectToAction("Index"));
            }
            catch (CustomException ex)
            {
                this.AddToastMessage(ex.Message, ToastType.Error);
                return(View("Create", vm));
            }
            catch (Exception ex)
            {
                this.AddToastMessage(Messages.GeneralError, ToastType.Error);
                return(View("Create", vm));
            }
        }
        public CreateProductResultModel Create(CreateProductModel model)
        {
            BaseClient client = new BaseClient();
            string     url    = "products/Create";

            return(client.Post <CreateProductResultModel, CreateProductModel>(url, model));
        }
Exemplo n.º 14
0
 public ActionResult ChangeProduct(CreateProductModel model)
 {
     service.UpdateProduct(new Store.BLL.DTO.ProductDTO {
         Price = model.Product.Price, Id = model.Product.Id, Category = service.GetCategory(model.Product.Category.Id), Name = model.Product.Name, Description = model.Product.Description
     });
     return(RedirectToAction("Index"));
 }
Exemplo n.º 15
0
        public async Task <CreateProductResultModel> CreateAsync([FromBody] CreateProductModel model, CancellationToken ct)
        {
            var result = await this.mediator.SendAsync(new CreateProductCommand { Code = model.Code, Name = model.Name, Price = model.Price }, ct);

            return(new CreateProductResultModel {
                Id = result.Id
            });
        }
Exemplo n.º 16
0
        public async Task <IActionResult> CreateProduct(CreateProductModel model)
        {
            var entity = ProductEntity.Create(model.Name, model.Price, model.Quantity);
            await storageTableService.Create(entity);

            ViewBag.Message = "Product was created correctly";
            return(RedirectToAction(nameof(ProductIndex)));
        }
Exemplo n.º 17
0
 /// <summary>
 /// Insert new Product
 /// </summary>
 /// <param name="newProductModel">Product Model of Insertion</param>
 public void Create(CreateProductModel newProductModel)
 {
     //Insert Product
     _productService.Create(newProductModel.Name,
                            newProductModel.Unit,
                            newProductModel.Price,
                            _categoryService.GetById(newProductModel.CategoryId));
 }
Exemplo n.º 18
0
        public ActionResult ProductEntry(CreateProductModel md)
        {
            if (ModelState.IsValid)
            {
                string currentUser = HttpContext.User.Identity.Name;
                int    ProductId   = md.FormSubmit.ProductId;
                if (ProductId == 0)
                {
                    bool returnresult = _accountService.CreateProduct(md.FormSubmit.SubCategoryId, md.FormSubmit.SupplierID,
                                                                      md.FormSubmit.ProductName, md.FormSubmit.ProductDesc,
                                                                      currentUser, md.FormSubmit.ProductType);
                    if (returnresult == true)
                    {
                        ModelState.Clear();
                        ViewBag.SuccessMsg = "Product created successfully";
                    }
                    else
                    {
                        ViewBag.SuccessMsg = "Error raised while creating product successfully";
                    }
                }
                else
                {
                    bool returnresult = _accountService.UpdateProduct(md.FormSubmit.ProductId, md.FormSubmit.SubCategoryId, md.FormSubmit.SupplierID,
                                                                      md.FormSubmit.ProductName, md.FormSubmit.ProductDesc,
                                                                      currentUser);
                    if (returnresult == true)
                    {
                        ModelState.Clear();
                        ViewBag.SuccessMsg = "Product information updated successfully";
                    }
                    else
                    {
                        ViewBag.Failuremessage = "Unable to update please try again later!";
                    }
                }
            }

            ViewBag.CategoryList    = _accountService.GetAllCategory(); //_accountService.SubCategory();
            ViewBag.SubCategoryList = _accountService.SubCategory();
            ViewBag.SupplierList    = _accountService.SupplierList();
            CreateProductModel     cpm            = new CreateProductModel();
            List <ProductDataList> AllProductData = _accountService.ProductDataList();
            ProductDisplay         model          = new ProductDisplay();

            model.ProductDataList = AllProductData;
            cpm.DisplayData       = model;
            model.ProductType     = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "Return", Value = "Return"
                },
                new SelectListItem {
                    Text = "Non Return", Value = "Non Return"
                },
            };
            return(View(cpm));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Load Page
        /// </summary>
        /// <returns>ViewModel Empty</returns>
        public ActionResult Create()
        {
            var vm = new CreateProductModel()
            {
                CategoryList = _categoryService.List().OrderBy(x => x.Name).ToList()
            };

            return(View(vm));
        }
Exemplo n.º 20
0
        public ActionResult CreateProduct(CreateProductModel model)
        {
            var cat = service.GetCategories().Single(d => d.Id == model.Product.Category.Id);

            service.CreateProduct(new Store.BLL.DTO.ProductDTO {
                Price = model.Product.Price, Id = model.Product.Id, Category = cat, Name = model.Product.Name, Description = model.Product.Description
            });
            return(RedirectToAction("Index"));
        }
Exemplo n.º 21
0
        public IActionResult Create(CreateProductModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.File != null)
                {
                    //check whether the file is an image
                    //FF D8 = 255 216

                    Stream file       = model.File.OpenReadStream();
                    int    firstByte  = file.ReadByte();
                    int    secondByte = file.ReadByte();  //position moved to 2

                    if (firstByte == 255 && secondByte == 216 && Path.GetExtension(model.File.FileName) == ".jpg" &&
                        file.Length < 4194304
                        )
                    {
                        //continue to uploading the file
                        string absolutePath = _host.WebRootPath + @"\images\";
                        string uniqueName   = Guid.NewGuid().ToString() + Path.GetExtension(model.File.FileName);

                        file.Position = 0;

                        MemoryStream ms = new MemoryStream();
                        file.CopyTo(ms);
                        ms.Position = 0;


                        System.IO.File.WriteAllBytes(absolutePath + uniqueName, ms.ToArray());

                        model.Product.ImageUrl    = @"\images\" + uniqueName;
                        model.Product.Description = HtmlEncoder.Default.Encode(model.Product.Description);
                        model.Product.Name        = HtmlEncoder.Default.Encode(model.Product.Name);
                        model.Product.CategoryId  = 1;
                        _prodService.AddProduct(model.Product);
                        TempData["info"] = "File   accepted";
                    }
                    else
                    {
                        TempData["warning"] = "File not accepted";
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "No file was uploaded");
                }
            }
            else
            {
                TempData["warning"] = "Check your inputs";

                ModelState.AddModelError(string.Empty, "Check your inputs");
            }


            return(View());
        }
Exemplo n.º 22
0
        private void FillProductPremium(CreateProductModel model)
        {
            var userDetail = _accessService.GetUserDetailByIdUser(Microsoft.AspNet.Identity.IdentityExtensions.GetUserId(User.Identity));

            if (userDetail != null && userDetail.IsPremium)
            {
                model.ShowProductPremium = userDetail.IsPremium;
            }
        }
Exemplo n.º 23
0
        public async Task <IActionResult> Create([Bind("Title,MPN,Price")] CreateProductModel model)
        {
            if (ModelState.IsValid)
            {
                await _service.CreateAsync(new CreateProductServiceModel(model));

                return(RedirectToAction(nameof(Index), new { repository = this.HttpContext.GetRequestedRepository() }));
            }
            return(View(model));
        }
Exemplo n.º 24
0
        public ActionResult Create()
        {
            PopulateSectionDropDownList();
            PopulateBrandDropDownList();
            CreateProductModel model = new CreateProductModel();

            model.colors = new List <ColorModel>();
            model.sizes  = new List <SizeModel>();
            return(View(model));
        }
Exemplo n.º 25
0
        public async Task <ActionResult <ProductDto> > CreateProduct([FromForm] CreateProductModel productModel)
        {
            var result = await _mediator.Send(new CreateProductCommand
            {
                ProductDto = _mapper.Map <ProductDto>(productModel),
                Photo      = productModel.Photo != null ? new FileAdapter(productModel.Photo) : null
            });

            return(Ok(result));
        }
        public IActionResult Create(CreateProductModel model)
        {
            var name        = model.Name.UrlDecode();
            var price       = model.Price;
            var description = model.Description.UrlDecode();
            var type        = Enum.Parse <Type>(model.Type);

            this.productService.AddProduct(name, price, description, type);
            return(new RedirectResult("/"));
        }
Exemplo n.º 27
0
        public async Task <IActionResult> Create([FromBody] CreateProductModel model)
        {
            var productId = Guid.NewGuid();

            var useCase = new CreateProduct(productId, model.Name, model.Price);
            var cmd     = new Command <CreateProduct>(useCase);

            var product = await _commandHandler.Execute <Product>(cmd);

            return(Ok(ProductModel.FromAggregateRoot(product)));
        }
        public async Task <IActionResult> PostProduct([FromBody] CreateProductModel product)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _createProductCommand.Execute(product);

            return(CreatedAtAction("GetProduct", new { id = product.ProductId }, product));
        }
Exemplo n.º 29
0
        string BuildProduct()
        {
            var model = new CreateProductModel
            {
                Name     = "test-product",
                Price    = 5000,
                Quantity = 5
            };

            return(JsonConvert.SerializeObject(model));
        }
Exemplo n.º 30
0
        public override async Task <ActionResult> Create()
        {
            var categories = await GetEntities <IEnumerable <ProductCategory> >(Endpoints.ProductCategory);

            var createModel = new CreateProductModel
            {
                Categories = GetDropDownList(categories)
            };

            return(View(createModel));
        }
Exemplo n.º 31
0
        public ActionResult Create(CreateProductModel model)
        {
            string userId = User.Identity.GetUserId();
            bool isFirstIteration = true;

            Product product = new Product
            {
                Name = model.Name,
                CategoryId = model.CategoryId,
                MaterialId = model.MaterialId,
                Price = model.Price,
                DaysToManufacture = model.DaysToManufacture,
                UserId = userId,
                DateAdded = DateTime.Now
            };

            this.productRepository.Add(product);
            this.productRepository.SaveChanges();

            string relativePath = String.Format(@"~/Images/{0}/Products/{1}/", userId, product.Id);
            string directory = Server.MapPath(relativePath);

            Directory.CreateDirectory(directory);

            foreach (HttpPostedFileBase image in model.Images)
            {
                if (image == null)
                {
                    if (model.Images.Count() == 1)
                    {
                        product.Images.Add(new ProductImage
                        {
                            Path = "~/Content/Images/image-not-found.png",
                            ContentType = "image/png",
                            IsMain = true,
                            Size = 104000
                        });

                        break;
                    }
                }

                string formatExtension = Path.GetExtension(image.FileName);
                string imageNewName = Guid.NewGuid().ToString() + formatExtension;
                string fullpath = Path.Combine(directory, imageNewName);
                string fullRelativePath = relativePath + imageNewName;

                image.SaveAs(fullpath);

                product.Images.Add(new ProductImage
                {
                    Path = fullRelativePath,
                    ContentType = image.ContentType,
                    Size = image.InputStream.Length,
                    IsMain = isFirstIteration ? true : false
                });
            }

            this.productRepository.SaveChanges();
            this.productRepository.Dispose();

            return RedirectToAction("Index", "Products");
        }