public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } var products = _productServices.GetProductById(Product.Id); var item = _itemServices.GetItemById(Product.Id); products.Name = Product.Name; products.Description = Product.Description; item.Price = Product.Price; item.QuantityInStock = Product.QuantityInStock; _userServices.SaveChanges(); if (Product.Picture?.Length > 0) { string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Images", Product.Id + ".jpg"); using (var stream = new FileStream(filePath, FileMode.Create)) { Product.Picture.CopyTo(stream); } } return(RedirectToPage("index")); }
public HttpResponseMessage Get(int id) { var item = _itemServices.GetItemById(id); if (item != null) { return(Request.CreateResponse(HttpStatusCode.OK, item)); } return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Item not found")); }
public ItemDTO GetItem(int id) { ItemDTO item = _itemLogc.GetItemById(id); _logger.LogInformation($"Start: Getting OrderItem {item}"); if (item == null) { _logger.LogInformation($"Somthing went wrong GetItem {id}"); throw new ArgumentException($"Cannot get item by item id : {id}", nameof(id)); } _logger.LogInformation($"Complete: Getting OrderItem {id}, {item}"); return(item); }
public IActionResult OnPost() { var products = _productServices.GetProductById(Product.Id); var item = _itemServices.GetItemById(Product.Id); _productServices.RemoveProduct(products); _itemServices.RemoveItem(item); _userServices.SaveChanges(); string filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Images", Product.Id + ".jpg"); if (System.IO.File.Exists(filePath)) { System.IO.File.Delete(filePath); } return(RedirectToPage("Index")); }
public IHttpActionResult GetItemById(int id) { var result = _itemservices.GetItemById(id); return(Ok(result)); }