public CreateProductModelResult(CreateProductModel createProductModel) { IsInStock = createProductModel.IsInStock; Name = createProductModel.Name; Sku = createProductModel.Sku; StoreId = createProductModel.StoreId; }
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()); }
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 })); }
// // GET: /Admin/Product/Create public ActionResult Create() { var model = new CreateProductModel(); model.AllCategories = _productCategoryService.GetProductCategorySelectList(model.CategoryName, GlobalHelper.SelectListDefaultOption); return(View(model)); }
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()); }
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); }
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); }
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 })); }
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")); }
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)); }
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")); }
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 }); }
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))); }
/// <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)); }
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)); }
/// <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)); }
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")); }
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()); }
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; } }
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)); }
public ActionResult Create() { PopulateSectionDropDownList(); PopulateBrandDropDownList(); CreateProductModel model = new CreateProductModel(); model.colors = new List <ColorModel>(); model.sizes = new List <SizeModel>(); return(View(model)); }
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("/")); }
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)); }
string BuildProduct() { var model = new CreateProductModel { Name = "test-product", Price = 5000, Quantity = 5 }; return(JsonConvert.SerializeObject(model)); }
public override async Task <ActionResult> Create() { var categories = await GetEntities <IEnumerable <ProductCategory> >(Endpoints.ProductCategory); var createModel = new CreateProductModel { Categories = GetDropDownList(categories) }; return(View(createModel)); }
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"); }