public ProductViewModel Create(ProductPostModel model) { var product = _mapper.Map <ProductModel>(model); var createdProduct = _productsService.Create(product); return(_mapper.Map <ProductViewModel>(createdProduct)); }
[HttpPost] //Create public ActionResult <Product> Create([FromBody] Product newProducts) { try { return(Ok(_service.Create(newProducts))); } catch (System.Exception err) { return(BadRequest(err.Message)); } }
public ActionResult Create(Products products) { if (ModelState.IsValid) { service.Create(products); return(RedirectToAction("Index", ControllerContext.RouteData.Values)); } ViewBag.CategoryID = new SelectList(service.GetCategoryList(), "CategoryID", "CategoryName", products.CategoryID); ViewBag.SupplierID = new SelectList(service.GetSupplierList(), "SupplierID", "CompanyName", products.SupplierID); return(View(products)); }
public ActionResult <Products> Create(Products product) { //var _productCategoryService = new ProductCategoryService() ; var productCategory = _productCategoryService.Get(product.categoryId); if (productCategory == null) { return(NotFound()); } product.Category = productCategory; // product.Category ={ product.Category.Id=prouctca} _productService.Create(product); return(CreatedAtRoute("Getproduct", new { id = product.Id.ToString() }, product)); }
public async Task <IActionResult> Create([FromForm] CreateRequest request) { var userId = User.GetUserId(); if (!userId.HasValue) { return(Unauthorized()); } var product = await _service.Create(request, userId.Value); return(Created("", new { Data = product })); }
private void SeedDbWithUserAndProduct(ApplicationDbContext dbContext, ProductsService productsService, Category category, Brand brand, IFormFile formfile) { for (int i = 0; i < 5; i++) { productsService.Create(new CreateProductBindingModel { Brand = brand.Name, Category = category.Name, Name = Guid.NewGuid().ToString(), Price = "15" }, formfile); dbContext.Users.Add(new ApplicationUser { UserName = $"{i}", FavouriteList = new FavouriteList(), ShoppingCart = new ShoppingCart { ShoppingCartProducts = new List <ShoppingCartProduct>() } }); dbContext.SaveChanges(); } }
// NOTE ANYTIME you need to use Async/Await you will return a Task public async Task <ActionResult <Product> > Create([FromBody] Product newProd) { try { // NOTE HttpContext == 'req' Profile userInfo = await HttpContext.GetUserInfoAsync <Profile>(); newProd.CreatorId = userInfo.Id; newProd.Creator = userInfo; return(Ok(_service.Create(newProd))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IActionResult Create(ProductsCreateVM viewmodel) { if (!ModelState.IsValid) { return(View(viewmodel)); } service.Create(viewmodel); if (viewmodel.SubmitInfo == "Done") { return(RedirectToAction(nameof(Index))); } else { return(RedirectToAction(nameof(Create))); } }
public ActionResult AdminProductAdd(AdminProductUpdate model, IEnumerable <HttpPostedFileBase> files) { var productservice = new ProductsService(); var photoservice = new ProductPhotoService(); var product = new Products() { ProductName = model.ProductName, UnitPrice = model.UnitPrice, CategoryID = model.CategoryID, ProductDetails = model.ProductDetails, Size = model.Size, Color = model.Color, UnitsInStock = model.UnitsInStock, Uptime = model.Uptime }; productservice.Create(product); foreach (var file in files) { if (file == null) { photoservice.Create(new ProductPhoto { ProductID = productservice.GetNewProductID(), PhotoPath = "https://bingshop.azurewebsites.net/Images/fff.jpg" }); } if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Images"), fileName); file.SaveAs(path); photoservice.Create(new ProductPhoto { ProductID = productservice.GetNewProductID(), PhotoPath = "https://bingshop.azurewebsites.net/Images/" + fileName }); } } return(View()); }
public ActionResult Create(Product p) { try { if (Request.Files != null && Request.Files.Count > 0) { HttpPostedFileBase productPhoto = Request.Files[0]; if (productPhoto.ContentLength > 0) { byte[] data = new byte[productPhoto.ContentLength]; productPhoto.InputStream.Read(data, 0, productPhoto.ContentLength); p.Photo = data; } } ProductsService service = new ProductsService(); service.Create(p); return(RedirectToAction("Index", "Home")); } catch { return(View()); } }
public ActionResult CreateEdit([Bind(Include = "ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit," + "UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")] ProductsFormModel products) { if (ModelState.IsValid) { if (products.ProductID == null) { products.ProductID = productsService.newProductID(); } Models.Products existing = productsService.SelectByID(products.ProductID); Models.Products model_products = FormmodelToModel(products); if (existing == null) { productsService.Create(model_products); productsService.Save(); return(Content(@"<script> alert('新增成功,該產品編號為 [ " + model_products.ProductID.ToString() + @" ],返回查詢頁面'); window.location = '/Products/Index'; </script>")); } else { productsService.Edit(model_products); productsService.Save(); return(Content(@"<script> alert('產品編號 [ " + products.ProductID + @" ] 修改成功,返回查詢頁面'); window.location = '/Products/Index'; </script>")); } } return(View(products)); }
public ActionResult <Product> Create(Product product) { _productsService.Create(product); return(CreatedAtRoute(new { id = product.Id.ToString() }, product)); }
public async Task <Products> Post([FromBody] Products cat) { return(await _context.Create(cat)); }
public async Task <IActionResult> OnPost() { await _productsService.Create(Product); return(RedirectToAction(nameof(Index))); }