public async Task <IActionResult> PutCustomerModel(int id, CustomerModel customerModel) { if (id != customerModel.CustomerId) { return(BadRequest()); } if (customerModel.ImageData != null) { _iimageService.DeleteImage(customerModel.CustomerImage); customerModel.CustomerImage = await _iimageService.SaveImage(customerModel.ImageData); } _context.Entry(customerModel).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> UpdateProduts(int id, [FromForm] ProductModel newProduct) { if (id != newProduct.ProductId) { return(BadRequest()); } if (newProduct.ImageData != null) { _iimageService.DeleteImage(newProduct.Image); newProduct.Image = await _iimageService.SaveImage(newProduct.ImageData); } _db.Entry(newProduct).State = EntityState.Modified; try { await _db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException error) { throw error; } return(NoContent()); }
public async Task <ActionResult <CustomerModel> > DeleteUserCustomer(int id) { var customerModel = await _context.CustomerModels.FindAsync(id); if (customerModel == null) { return(BadRequest()); } _context.CustomerModels.Remove(customerModel); await _context.SaveChangesAsync(); return(customerModel); }
public async Task <ActionResult <ProductModel> > AddProducts([FromBody] ProductModel newProduct) { try { Console.WriteLine("dddddddddddddddddddd"); newProduct.Image = await _iimageService.SaveImage(newProduct.ImageData); _db.ProductModels.Add(newProduct); await _db.SaveChangesAsync(); return(newProduct); } catch (Exception ex) { Console.WriteLine("dddddddddddddddddddd"); throw ex; } }