public async Task <IActionResult> updateProductAvailableStatus(int id, string status) { try { var product = _productservices.GetById(id); if (product == null) { string myJson = "{'message': " + "Not Found" + "}"; return(NotFound(myJson)); // return NotFound(); } else { product.status = status; await _productservices.UpdateAsync(product); return(Ok(product)); } //return BadRequest(); } catch (Exception obj) { return(Ok(obj.Message)); } }
public async Task <IActionResult> Edit(productEditViewModel model) { if (ModelState.IsValid) { var storeobj = _productservices.GetById(model.id); if (storeobj == null) { return(NotFound()); } storeobj.id = model.id; storeobj.name = model.name; storeobj.productcuisineid = model.productcuisineid; storeobj.foodtype = model.foodtype; storeobj.amount = model.amount; storeobj.description = model.description; storeobj.discounttype = model.discounttype; storeobj.discountamount = model.discountamount; storeobj.status = model.status; storeobj.fkmenuid = model.fkmenuid; if (model.img != null && model.img.Length > 0) { var uploadDir = @"uploads/product"; var fileName = Path.GetFileNameWithoutExtension(model.img.FileName); var extesion = Path.GetExtension(model.img.FileName); var webRootPath = _hostingEnvironment.WebRootPath; fileName = DateTime.UtcNow.ToString("yymmssfff") + fileName + extesion; var path = Path.Combine(webRootPath, uploadDir, fileName); await model.img.CopyToAsync(new FileStream(path, FileMode.Create)); storeobj.img = '/' + uploadDir + '/' + fileName; } await _productservices.UpdateAsync(storeobj); return(RedirectToAction(nameof(Index))); } else { return(View()); } }