/// <summary> /// Deletes a category. /// </summary> /// <param name="categoryDel">Category to delete</param> public void Delete(CategoryDTO categoryDel) { // Throws an exception for a null dto if (categoryDel == null) throw new ArgumentNullException("categoryDel", "categoryDel does not accept a null dto as an argument."); using (var context = new openTillEntities()) { var category = context.Categories.SingleOrDefault(c => c.Id == categoryDel.Id); // Throws an exception if no matching entry is found if (category == null) throw new InvalidOperationException("No entry matching the given category was found."); context.Categories.Remove(category); context.SaveChanges(); } }
/// <summary> /// Method calls on repository to update an exisiting field in the database. /// </summary> /// <param name="categoryToUpdate">Category that is to be updated.</param> public void Update(CategoryDTO categoryToUpdate) { _categoryRepository.Update(categoryToUpdate); }
/// <summary> /// Method calls on repository to insert a new category field into the database. /// </summary> /// <param name="categoryToInsert">Category Data Transfer Object to insert into the database.</param> public void Insert(CategoryDTO categoryToInsert) { _categoryRepository.Insert(categoryToInsert); }
/// <summary> /// Method calls on repository to remove a Category field from the database. /// </summary> /// <param name="categoryToDelete">Category that is to be removed from the database.</param> public void Delete(CategoryDTO categoryToDelete) { _categoryRepository.Delete(categoryToDelete); }
public ObservableCategory(CategoryDTO dto) { this.Id = dto.Id; this.Name = dto.Name; this.Description = dto.Description; }
/// <summary> /// Submits a new category for persistence. /// </summary> /// <param name="newCategory">New category to save</param> public void Insert(CategoryDTO newCategory) { // Throws an exception for a null dto if (newCategory == null) throw new ArgumentNullException("newCategory", "newCategory does not accept a null dto as an argument."); using (var context = new openTillEntities()) { // Throws an exception if a category with the given name already exists if (context.Categories.SingleOrDefault(c => c.Name == newCategory.Name) != null) throw new InvalidOperationException("A category with the given name already."); context.Categories.Add(Mapper.Map<Category>(newCategory)); context.SaveChanges(); } }
/// <summary> /// Updates an existing category. /// </summary> /// <param name="categoryUpdate">Category to update</param> public void Update(CategoryDTO categoryUpdate) { // Throws an exception for a null dto if (categoryUpdate == null) throw new ArgumentNullException("categoryUpdate", "categoryUpdate does not accept a null dto as an argument."); using (var context = new openTillEntities()) { var category = context.Categories.SingleOrDefault(c => c.Id == categoryUpdate.Id); // Throws an exception if the given category doesn't exist if (category == null) throw new InvalidOperationException("No entry matching the given category was found."); // Throws an exception if a category with the given name already exists if (context.Categories.SingleOrDefault(c => c.Name == categoryUpdate.Name) != null) throw new InvalidOperationException("A category with the given name already."); // Update existing category category.Name = categoryUpdate.Name; category.Description = category.Description; context.SaveChanges(); } }