Exemple #1
0
        public async Task <IReadOnlyCollection <ProjectDTO> > ReadDetailedAsync()
        {
            var projects = from p in _context.Projects
                           select new ProjectDTO
            {
                Id          = p.Id,
                Title       = p.Title,
                Description = p.Description,
                Location    = (p.Location == null) ? null : new LocationDTO()
                {
                    Id = p.Location.Id, City = p.Location.City, Country = p.Location.Country
                },
                Skills      = EntityConversionHelper.ConvertSkillsToSkillDTOs(p.Skills),
                Sparks      = EntityConversionHelper.ConvertSparksToSparkDTOs(p.Sparks),
                CreatedDate = p.CreatedDate,
                Category    = (p.Category == null) ? null : new CategoryDTO()
                {
                    Id = p.Category.Id, Name = p.Category.Name
                },
                Creator = (p.Creator == null) ? null : new UserDTO()
                {
                    Id = p.Creator.Id, Firstname = p.Creator.Firstname, Location = (p.Creator.Location == null) ? null : new LocationDTO()
                    {
                        Id = p.Creator.Location.Id, City = p.Creator.Location.City, Country = p.Location.Country
                    }, Mail = p.Creator.Mail, Skills = EntityConversionHelper.ConvertSkillsToSkillDTOs(p.Creator.Skills), Surname = p.Creator.Surname
                }
            };

            return(await projects.ToListAsync());
        }
Exemple #2
0
        public async Task <bool> UpdateAsync(int userId, UserDTO user)
        {
            var userToUpdate = await _context.Users.FindAsync(userId);

            _context.Users.Update(userToUpdate);

            userToUpdate.Firstname  = user.Firstname;
            userToUpdate.Surname    = user.Surname;
            userToUpdate.Mail       = user.Mail;
            userToUpdate.LocationId = user.Location?.Id;
            userToUpdate.Location   = (user.Location == null) ? null : new Location()
            {
                Id = user.Location.Id, City = user.Location.City, Country = user.Location.Country
            };
            userToUpdate.Skills = EntityConversionHelper.ConvertSkillDTOsToUserSkills(user.Skills, userId);

            return(await saveContextChanges() > 0);
        }
Exemple #3
0
        public async Task <IReadOnlyCollection <UserDTO> > ReadAsync()
        {
            var users = from u in _context.Users
                        select new UserDTO
            {
                Id        = u.Id,
                Firstname = u.Firstname,
                Surname   = u.Surname,
                Mail      = u.Mail,
                Location  = (u.Location == null) ? null : new LocationDTO()
                {
                    Id = u.Location.Id, City = u.Location.City, Country = u.Location.Country
                },
                Skills = EntityConversionHelper.ConvertSkillsToSkillDTOs(u.Skills)
            };

            return(await users.ToListAsync());
        }
Exemple #4
0
        public async Task <UserDTO> FindFromAzureUIdAsync(string azureUId)
        {
            var user = await _context.Users.AsNoTracking().Where(u => u.AzureUId == azureUId).FirstOrDefaultAsync();

            if (user is null)
            {
                return(null);
            }

            return(new UserDTO
            {
                Id = user.Id,
                Firstname = user.Firstname,
                Surname = user.Surname,
                Mail = user.Mail,
                Location = (user.Location == null) ? null : new LocationDTO()
                {
                    Id = user.Location.Id, City = user.Location.City, Country = user.Location.Country
                },
                Skills = EntityConversionHelper.ConvertSkillsToSkillDTOs(user.Skills)
            });
        }
Exemple #5
0
        public async Task <bool> UpdateAsync(ProjectDTO details)
        {
            var projectToUpdate = await _context.Projects.FindAsync(details.Id);

            _context.Projects.Update(projectToUpdate);

            projectToUpdate.Title       = details.Title;
            projectToUpdate.Description = details.Description;
            projectToUpdate.LocationId  = details.Location?.Id;
            projectToUpdate.Location    = (details.Location is null) ? null : new Location()
            {
                Id = details.Location.Id, City = details.Location.City, Country = details.Location.Country
            };
            projectToUpdate.Skills   = EntityConversionHelper.ConvertSkillDTOsToProjectSkills(details.Skills, details.Id);
            projectToUpdate.Sparks   = EntityConversionHelper.ConvertSparkDTOsToSparks(details.Sparks);
            projectToUpdate.Category = (details.Category is null) ? null : new Category()
            {
                Id = details.Category.Id, Name = details.Category.Name
            };

            return(await saveContextChanges() > 0);
        }
Exemple #6
0
        public async Task <ProjectDTO> FindAsync(int projectId)
        {
            var project = await _context.Projects.FindAsync(projectId);

            if (project is null)
            {
                return(null);
            }
            else
            {
                return new ProjectDTO
                       {
                           Id          = project.Id,
                           Title       = project.Title,
                           Description = project.Description,
                           Location    = (project.Location is null) ? null : new LocationDTO()
                           {
                               Id = project.Location.Id, City = project.Location.City, Country = project.Location.Country
                           },
                           Skills   = EntityConversionHelper.ConvertSkillsToSkillDTOs(project.Skills),
                           Sparks   = EntityConversionHelper.ConvertSparksToSparkDTOs(project.Sparks),
                           Category = (project.Category is null) ? null : new CategoryDTO()
                           {
                               Id = project.Category.Id, Name = project.Category.Name
                           },
                           CreatedDate = project.CreatedDate,
                           Creator     = (project.Creator == null) ? null : new UserDTO()
                           {
                               Id = project.Creator.Id, Firstname = project.Creator.Firstname, Location = (project.Creator.Location == null) ? null : new LocationDTO()
                               {
                                   Id = project.Creator.Location.Id, City = project.Creator.Location.City, Country = project.Location.Country
                               }, Mail = project.Creator.Mail, Skills = EntityConversionHelper.ConvertSkillsToSkillDTOs(project.Creator.Skills), Surname = project.Creator.Surname
                           }
                       }
            };
        }