private void OnAddFoodButtonClick(object sender, EventArgs e) { try { FoodDTO dto = FoodItemPresenter.GetInputs(); if (dto.Category == null) { CategoryDTO categoryDto = new CategoryDTO() { Name = FoodItemPresenter.GetNewCategoryName() }; newCategory = FoodTracker.AddCategory(categoryDto); dto.Category = newCategory; } FoodTracker.AddFood(dto); AddFoodView.DialogResult = DialogResult.OK; } catch (ValidationException vex) { MessageBox.Show(vex.Message); } }
public Food(string name, FoodCategory category, string description, int calories, double sugars, double fat, double saturates, double salt) { this.Name = name; this.Category = category; this.Description = description; this.Calories = calories; this.Sugars = sugars; this.Fat = fat; this.Saturates = saturates; this.Salt = salt; }
public void Add(FoodCategory foodCategory) { context.Categories.Add(foodCategory); context.SaveChanges(); if(foodCategory.Order == 0) { foodCategory.Order = foodCategory.Id; Edit(foodCategory); } }
public void Delete(FoodCategory foodCategory) { context.Categories.Remove(foodCategory); }
public void Edit(FoodCategory foodCategory) { context.Entry(foodCategory).State = System.Data.Entity.EntityState.Modified; }
public void Edit(FoodCategory fCategory) { }
public void Set(FoodCategory category) { CategoryItemView.CategoryName = category.Name; }
public void DeleteCategory(FoodCategory foodCategory) { if (foodCategory.Name == "Uncategorised") { throw new ArgumentException("Cannot delete the Uncategorised Category."); } IList<Food> foodsInCat = GetFoodByCategory(foodCategory); FoodCategory uncategorised = UnitOfWork.FoodCategoryRepository.GetAll().Where(o => o.Name == "Uncategorised").First(); foreach (Food food in foodsInCat) { food.Category = uncategorised; UnitOfWork.FoodRepository.Edit(food); } try { UnitOfWork.FoodCategoryRepository.Delete(foodCategory); UnitOfWork.Save(); } catch (InvalidOperationException) { throw new ArgumentException("This food does not exist, hence can't be deleted."); } }
public void SwapCategoryOrder(FoodCategory foodCategory1, FoodCategory foodCategory2) { int tempOrder = foodCategory1.Order; foodCategory1.Order = foodCategory2.Order; foodCategory2.Order = tempOrder; UnitOfWork.FoodCategoryRepository.Edit(foodCategory1); UnitOfWork.FoodCategoryRepository.Edit(foodCategory2); UnitOfWork.Save(); }
public void EditFoodCategory(CategoryDTO categoryDto, FoodCategory foodCategory) { FoodCategory editedCategory = parseCategoryDTO(categoryDto); Validator.ValidateObject(editedCategory, new ValidationContext(editedCategory), true); if (editedCategory.Name.ToLower() != foodCategory.Name.ToLower() && UnitOfWork.FoodCategoryRepository.GetAll().Where(o => o.Name.ToLower().Equals(editedCategory.Name.ToLower())).Any()) { throw new ArgumentException("A category with this name already exists."); } foodCategory.Update(editedCategory); UnitOfWork.FoodCategoryRepository.Edit(foodCategory); }
public IList<Food> GetFoodByCategory(FoodCategory category) { return UnitOfWork.FoodRepository.GetByCategory(category); }
public void UpdateCategories(FoodCategory selectedCategory) { CategoryLookupPresenter.UpdateCategories(selectedCategory); }
public IList<Food> GetByCategory(FoodCategory fCat) { throw new NotImplementedException(); }
public void Delete(FoodCategory fCategory) { }
public void UpdateCategories(FoodCategory selectedFCat) { IList<FoodCategory> categories; if (ShowEmptyCategories) { categories = FoodTracker.GetAllFoodCategories(ShowUncategorised); } else { categories = FoodTracker.GetNonEmptyFoodCategories(ShowUncategorised); } if (categories.Count == 0) { CategoryLookupView.SelectedCategoryIndex = -1; } CategoryLookupView.Categories = categories; CategoryLookupView.SelectedCategory = selectedFCat; }
public void Update(FoodCategory editedCategory) { Name = editedCategory.Name; }
public IList<Food> GetByCategory(FoodCategory fCat) { return context.Foods.Where(x => x.Category.Id == fCat.Id).ToList(); }
public void Add(FoodCategory fCategory) { cats.Add(fCategory); }