/// <summary> /// This method removes and existing product from the DbContext and saves it /// </summary> /// <param name="product"></param> /// <returns></returns> public async Task DeleteProductAsync(vacunados product) { try { dbContext.Product.Remove(product); await dbContext.SaveChangesAsync(); } catch (Exception) { throw; } }
/// <summary> /// This method add a new product to the DbContext and saves it /// </summary> /// <param name="product"></param> /// <returns></returns> public async Task <vacunados> AddProductAsync(vacunados product) { try { dbContext.Product.Add(product); await dbContext.SaveChangesAsync(); } catch (Exception) { throw; } return(product); }
/// <summary> /// This method update and existing product and saves the changes /// </summary> /// <param name="product"></param> /// <returns></returns> public async Task <vacunados> UpdateProductAsync(vacunados product) { try { var productExist = dbContext.Product.FirstOrDefault(p => p.Id == product.Id); if (productExist != null) { dbContext.Update(product); await dbContext.SaveChangesAsync(); } } catch (Exception) { throw; } return(product); }