public async Task <int> UpdateProductListType(ProductListTypeDto model) { var productToUpdate = await _skinHubAppDbContext.ProductType.FindAsync(model.ID); if (productToUpdate != null) { productToUpdate.Name = model.Name; _skinHubAppDbContext.Entry(productToUpdate).State = EntityState.Modified; await _skinHubAppDbContext.SaveChangesAsync(); return(model.ID); } return(0); }
public async Task <ProductListTypeDto> GetProductListTypeByID(int id) { var productTypeByID = await _skinHubAppDbContext.ProductListType.Include(c => c.ProductType).FirstOrDefaultAsync(g => g.ID == id); if (productTypeByID != null) { var model = new ProductListTypeDto { ID = productTypeByID.ID, Name = productTypeByID.Name, ProductTypeID = productTypeByID.ProductTypeID, ProductType = productTypeByID.ProductType.Name, }; return(model); } return(null); }
public async Task <IActionResult> Update([FromBody] ProductListTypeDto model) { try { if (ModelState.IsValid) { var update = await _productTypeServices.GetProductListTypeByID(model.ID); if (update != null) { await _productTypeServices.UpdateProductListType(model); return(Ok($"{model.Name} updated Successfully")); } } return(BadRequest("Update failed, Please try again")); } catch (Exception ex) { return(BadRequest($"{ex.Message}, Error! Your task failed, Please try again")); } }