public async Task <ActionResult <Product> > PostProduct([FromForm] ProductWithCategory productWithCategory) { var product = new Product() { Name = productWithCategory.Name, Price = productWithCategory.Price, Description = productWithCategory.Description, Active = productWithCategory.Active, ImgSrc = String.Format("{0}://{1}{2}/Images/{3}", Request.Scheme, Request.Host, Request.PathBase, productWithCategory.ImgName) }; product.ImgName = await SaveImage(productWithCategory.ImgFile); _context.Products.Add(product); await _context.SaveChangesAsync(); var productCategory = new Productcategory() { Productid = product.Id, Categoryname = productWithCategory.Categoryname }; _context.Productcategories.Add(productCategory); await _context.SaveChangesAsync(); return(CreatedAtAction("GetProduct", new { id = product.Id }, product)); }
public ActionResult Delete(string Id) { Productcategory productcategoryToDelete = Context.Find(Id); if (productcategoryToDelete == null) { return(HttpNotFound()); } else { return(View(productcategoryToDelete)); } }
public ActionResult Edit(string Id) { Productcategory productcategory = Context.Find(Id); if (productcategory == null) { return(HttpNotFound()); } else { return(View(productcategory)); } }
public async Task <ActionResult> Put(int catid, [FromBody] Productcategory obj) { var target = await _context.Productcategory.SingleOrDefaultAsync(nobj => nobj.Catid == catid); if (target != null && ModelState.IsValid) { _context.Entry(target).CurrentValues.SetValues(obj); await _context.SaveChangesAsync(); return(Ok()); } return(BadRequest()); }
public ActionResult Create(Productcategory productcategory) { if (!ModelState.IsValid) { return View(productcategory) } else { Context.Insert(productcategory); Context.Commit(); return(RedirectToAction("Index")); } }
public async Task <ActionResult <Productcategory> > Post([FromBody] Productcategory obj) { if (!ModelState.IsValid) { return(BadRequest()); } else { _context.Productcategory.Add(obj); await _context.SaveChangesAsync(); return(Created("api/Productcategory", obj)); } }
public ActionResult ConfirmDelete(string Id) { Productcategory productcategoryToDelete = Context.Find(Id); if (productcategoryToDelete == null) { return(HttpNotFound()); } else { Context.Delete(Id); Context.Commit(); return(RedirectToAction("Index")); } }
public IHttpActionResult GetAllProductCategory() { List <Productcategory> pc = new List <Productcategory>(); try { //DataSet ds=new DataSet(); //SqlConnection sqlcon = new SqlConnection(connection); //string storedprocedure = "BagByte_01_GetProductCategory"; //SqlCommand sqlcmd = new SqlCommand(storedprocedure, sqlcon); ////sqlcmd.Parameters.AddWithValue("@UserID", UserID); ////sqlcmd.CommandType = CommandType.StoredProcedure; //sqlcon.Open(); //SqlDataAdapter adapter = new SqlDataAdapter(sqlcmd); //adapter.Fill(ds); //sqlcon.Close(); string Path = "D:/VINAY/BagByteAPI/BagByteAPI/Images/ProductCategory"; string[] Images = Directory.GetFiles(Path); long ProductID = 0; for (int i = 0; i < Images.Length; i++) { ProductID++; Productcategory temppc = new Productcategory(); temppc.ProductID = ProductID; temppc.ProCatName = "Product_" + Convert.ToString(ProductID); //temppc.ProImage=(byte[])(ds.Tables[0].Rows[i]["ProductCategoryImage"]); temppc.ImageLocation = Images[i]; temppc.ImageName = "Product_" + Convert.ToString(ProductID); pc.Add(temppc); } } catch (Exception ex) { return(ResponseMessage(Request.CreateResponse(ex.ToString()))); } return(Ok(pc)); }
public async Task <IActionResult> OnPostAddNewCategoryAsync(Productcategory model) { if (!ModelState.IsValid) { return(RedirectToAction("AddCategory")); } var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } await _db.Productcategories.AddAsync(model); await _db.SaveChangesAsync(); return(RedirectToAction("Categories")); }
public ActionResult Edit(Productcategory product, string Id, HttpPostedFileBase file) { Productcategory productcategoryToEdit = Context.Find(Id); if (productcategoryToEdit == null) { return(HttpNotFound()); } else { if (!ModelState.IsValid) { return(View(product)); } productcategoryToEdit.category = product.category; Context.Commit(); return(RedirectToAction("Index")); } }
public async Task <IActionResult> OnPostUpdateCategoryDetailsAsync(Productcategory model) { if (!ModelState.IsValid) { return(RedirectToAction("Categories")); } var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } var category = _db.Productcategories.First(o => o.CategoryId == model.CategoryId); if (category == null) { return(RedirectToAction("Categories")); } category.CategoryName = model.CategoryName; _db.Productcategories.Update(category); await _db.SaveChangesAsync(); return(RedirectToAction("Categories")); }
public ActionResult Create() { Productcategory productcategory = new Productcategory(); return(View(productcategory)); }