예제 #1
0
        public async Task <IActionResult> Follow([FromBody] FollowingCreateDto following)
        {
            if (following == null)
            {
                return(BadRequest());
            }

            var project = await _db.Projects.SingleOrDefaultAsync(p => p.ProjectId == following.ProjectId);

            if (project == null)
            {
                return(NotFound());
            }

            var existingFollowing = await _db.FollowedProjects.Include(f => f.Project).SingleOrDefaultAsync(f => f.ProjectId == following.ProjectId && f.UserId == UserId);

            if (existingFollowing != null)
            {
                return(Ok(new FollowingDto(existingFollowing)));
            }

            var newFollowing = new FollowedProjects {
                UserId = UserId, ProjectId = following.ProjectId, TimeCreated = DateTime.UtcNow
            };

            _db.FollowedProjects.Add(newFollowing);
            await _db.SaveChangesAsync();

            await _db.Entry(newFollowing).Reference(f => f.Project).LoadAsync();

            return(Ok(new FollowingDto(newFollowing)));
        }
예제 #2
0
        public FollowingDto(FollowedProjects following)
        {
            if (following != null)
            {
                FollowingId = following.FollowedProjectsId;
                UserId      = following.UserId;
                ProjectId   = following.ProjectId;
                TimeCreated = following.TimeCreated;

                if (following.Project != null)
                {
                    Avatar      = following.Project.Avatar;
                    ProjectSlug = following.Project.Slug;
                    ProjectName = following.Project.Name;
                }
            }
        }