public void Update(DalCategory entity)
 {
     var updatedCategory = entity.ToCategory();
     var existedCategory = _dbContext.Entry<Category>(_dbContext.Set<Category>().Find(updatedCategory.CategoryId));
     if (existedCategory == null)
     {
         return;
     }
     existedCategory.State = EntityState.Modified;
     existedCategory.Entity.IsBlocked = entity.IsBlocked;
     existedCategory.Entity.IsConfirmed = entity.IsConfirmed;
 }
Exemplo n.º 2
0
 public void Delete(DalCategory entity)
 {
     if (entity == null) throw new ArgumentNullException("entity");
     Delete(entity.Id);
 }
Exemplo n.º 3
0
        private void UpdateInfo(Category cat, DalCategory dalCat)
        {
            if (cat == null || dalCat == null) throw new ArgumentNullException();

            cat.Id = dalCat.Id;
            cat.Name = dalCat.Name;
            cat.Description = dalCat.Description;
            cat.DateCreated = dalCat.DateCreated;
            cat.Category_Id = dalCat.ParentCategoryId;
        }
Exemplo n.º 4
0
        private Category ToOrmCategory(DalCategory cat)
        {
            if (cat == null) return null;

            var topics = cat.Topics ?? new List<DalTopic>();

            var dbSetTopics = _context.Set<Topic>();

            var actualTopics = topics.Select(t => dbSetTopics.SingleOrDefault(tt => tt.Id == t.Id)).ToList();

            var newCat = new Category {Topics = actualTopics};
            UpdateInfo(newCat, cat);

            return newCat;
        }
Exemplo n.º 5
0
 public void Update(DalCategory entity)
 {
     if (entity == null) throw new ArgumentNullException("entity");
     var existedEntity = _dbSetCategories.Find(entity.Id);
     UpdateInfo(existedEntity, entity);
 }
Exemplo n.º 6
0
 public void Insert(DalCategory entity)
 {
     if (entity == null) throw new ArgumentNullException("entity");
     _dbSetCategories.Add(ToOrmCategory(entity));
 }
 public void Delete(DalCategory entity)
 {
     var category = entity.ToCategory();
     category = _dbContext.Set<Category>().Single(c => c.CategoryId == category.CategoryId);
     _dbContext.Set<Category>().Remove(category);
 }
 public void Create(DalCategory entity)
 {
     var category = entity.ToCategory();
     _dbContext.Set<Category>().Add(category);
 }