Example #1
0
        public ToDoTask GetById(long id)
        {
            ToDoTaskEntity entity = _lifeManagerRepository.LoadToDoTask(id);

            if (entity == null)
            {
                return(null);
            }

            return(_toDoTaskMapper.ToDomain(entity));
        }
Example #2
0
        public ToDoTask ToDomain(ToDoTaskEntity entity)
        {
            ToDoTask domain = new ToDoTask {
                Status       = entity.Status,
                Priority     = entity.Priority,
                Dependencies = entity.Dependencies == null
                    ? new List <long>()
                    : entity.Dependencies.Select(dependencyEntity => dependencyEntity.ToDoTaskDependencyId).ToList()
            };

            _taskMapper.ToDomain(entity, domain);

            return(domain);
        }
Example #3
0
        public ToDoTaskEntity ToEntity(ToDoTask domain)
        {
            ToDoTaskEntity entity = new ToDoTaskEntity {
                Status       = domain.Status,
                Priority     = domain.Priority,
                Dependencies = domain.Dependencies.Select(dependencyId => new ToDoTaskDependencyEntity {
                    ToDoTaskEntityId     = domain.Id,
                    ToDoTaskDependencyId = dependencyId
                }).ToList()
            };

            _taskMapper.ToEntity(domain, entity);

            return(entity);
        }
Example #4
0
        public void SaveEntity <T>(T entity) where T : class, IItemEntity
        {
            switch (entity)
            {
            case ToDoTaskEntity toDoTaskEntity:
                if (toDoTaskEntity.Id == 0)
                {
                    break;
                }

                ToDoTaskEntity existing = LoadToDoTask(entity.Id);
                foreach (ToDoTaskDependencyEntity existingDependency in existing.Dependencies)
                {
                    if (toDoTaskEntity.Dependencies.All(e => e.ToDoTaskDependencyId != existingDependency.ToDoTaskDependencyId))
                    {
                        _dbContext.Entry(existingDependency).State = EntityState.Deleted;
                    }
                }

                _dbContext.SaveChanges();
                DetachedEntityOrNull(existing);

                foreach (ToDoTaskDependencyEntity dependency in toDoTaskEntity.Dependencies)
                {
                    _dbContext.Entry(dependency).State = existing.Dependencies
                                                         .Any(e => dependency.ToDoTaskDependencyId == e.ToDoTaskDependencyId)
                            ? EntityState.Modified
                            : EntityState.Added;
                }

                break;
            }

            _dbContext.Set <T>().Update(entity);
            _dbContext.SaveChanges();
        }