/// <summary> /// Add a provider /// </summary> /// <param name="provider"></param> /// <returns></returns> public async Task <bool> AddAsync(Provider provider) { context.Provider.Add(provider); await context.SaveChangesAsync(); return(true); }
/// <summary> /// Add a entity /// </summary> /// <param name="entity"></param> /// <returns></returns> public async Task <bool> AddAsync(T entity) { context.Set <T>().Add(entity); await context.SaveChangesAsync(); return(true); }
/// <summary> /// Add a Product /// </summary> /// <param name="product"></param> /// <returns></returns> public async Task <bool> AddAsync(Product product) { Dictionary <string, List <string> > errors = null; var category = context.Category.Find(product.CategoryId); if (category == null) { errors = new Dictionary <string, List <string> > { { "CategoryId", new List <string>() { $"The Category with id '{product.CategoryId}' does not exist" } } }; } else if (category.Status == false) { errors = new Dictionary <string, List <string> > { { "Category", new List <string>() { $"The Category '{category.Name}' is INACTIVE" } } }; } if (errors != null && errors.Count > 0) { customError = new CustomError(400, errors); return(false); } context.Product.Add(product); await context.SaveChangesAsync(); return(true); }