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