예제 #1
0
        public int Create(Category categoryToCreate)
        {
            if (categoryToCreate == null)
            {
                throw new Exception("The Category sent in for creation is null.");
            }

            base.UpdateIsDeletedToFalse(categoryToCreate);
            base.UpdateDateAdded(categoryToCreate);

            db.Categories.Add(categoryToCreate);
            db.SaveChanges();
            int idOfCategory = categoryToCreate.ID;

            return idOfCategory;
        }
예제 #2
0
 public void Delete(Category categoryToDelete)
 {
     Delete(categoryToDelete.ID);
 }
예제 #3
0
        public int Update(Category updatedCategory)
        {
            Category categoryToUpdate = db.Categories.SingleOrDefault(c => c.ID == updatedCategory.ID && c.IsDeleted == false);

            if (categoryToUpdate == null)
            {
                throw new Exception("No Category exists with the id " + updatedCategory.ID);
            }

            base.UpdateDateUpdated(updatedCategory);

            db.Categories.AddOrUpdate(c => c.ID, updatedCategory);
            db.SaveChanges();
            int idOfCategory = categoryToUpdate.ID;

            return idOfCategory;
        }
예제 #4
0
 public Category Get(Category categoryToGet)
 {
     return Get(categoryToGet.Name);
 }
예제 #5
0
 public void Destroy(Category categoryToDestroy)
 {
     Destroy(categoryToDestroy.ID);
 }
예제 #6
0
 private CategoryDisplayViewModel ConvertCategoryToCategoryDisplayViewModel(Category model)
 {
     return new CategoryDisplayViewModel
     {
         Name = model.Name,
         IsDeleted = model.IsDeleted,
         DateAdded = model.DateAdded,
         DateDeleted = model.DateDeleted,
         DateUpdated = model.DateUpdated
     };
 }