Пример #1
0
        public IActionResult getCommentsByProjects(int projectId)
        {
            List <Models.Commentary> commentarys = _db.Commentary.ToList().FindAll(p => p.IdProject == projectId);
            var coments = new List <ViewModels.Commentary>();

            foreach (var com in commentarys)
            {
                var comment = new ViewModels.Commentary();
                comment.Id          = com.Id;
                comment.projectid   = com.IdProject;
                comment.dataCreated = com.DateCreated;
                comment.content     = com.Content;
                comment.userid      = com.IdUserProfile;

                var userProf = _db.UserProfile.FirstOrDefault(p => p.Id == com.IdUserProfile);

                var mini = new UserProfileMini
                {
                    firstName  = userProf.FirstName,
                    secondName = userProf.SecondName,
                    id         = userProf.Id,
                    urlPhoto   = userProf.UrlPhoto
                };
                comment.userProfile = mini;
                coments.Add(comment);
            }
            return(new ObjectResult(coments));
        }
Пример #2
0
        public IActionResult getProjectById(int id, int userId)
        {
            var display           = new Display();
            var projectController = new ProjectController(_db);
            var profile           = new UserProfileMini();
            var rating            = _db.Rating.FirstOrDefault(p => (p.UserId == userId) && (p.ProjectId == id));

            projectController.RefreshDate();
            var project     = _db.Project.FirstOrDefault(p => p.Id == id);
            var user        = _db.UserProfile.FirstOrDefault(p => (p.Id == project.CreateUserId));
            var checkStatus = _db.FollowsUser.ToList().FirstOrDefault(p => (p.UserId == userId) && (p.ProjectId == id));

            CheckStatusProject(checkStatus, project);

            Checkrating(rating, project);

            var tags       = _db.InstructionTag.ToList();
            var tagsString = new List <string>();

            tags = tags.FindAll(p => p.ProjectId == id);
            foreach (var tag in tags)
            {
                var bufTag = _db.Tag.FirstOrDefault(p => p.Id == tag.IdTags);
                if (bufTag != null)
                {
                    tagsString.Add(bufTag.Name);
                }
                else
                {
                    tagsString.Add("");
                }
            }

            profile.id         = user.Id;
            profile.firstName  = user.FirstName;
            profile.secondName = user.SecondName;
            profile.urlPhoto   = user.UrlPhoto;

            display.project      = project;
            display.tags         = tagsString;
            display.finansalGoal = GetGoals(id);
            display.creater      = profile;


            return(new ObjectResult(display));
        }
Пример #3
0
        public IActionResult addCommentInProject([FromBody] ViewModels.Commentary model)
        {
            var project    = _db.Project.FirstOrDefault(p => p.Id == model.projectid);
            var commentary = new Models.Commentary();

            commentary.Content     = model.content;
            commentary.DateCreated = date.ToString();

            commentary.Project       = project;
            commentary.IdProject     = project.Id;
            commentary.UserProfile   = _db.UserProfile.FirstOrDefault(p => p.Id == model.userid);
            commentary.IdUserProfile = commentary.UserProfile.Id;

            _db.Commentary.Add(commentary);
            project.ProjectComments.Add(commentary);
            UpdateProjectDB(project);

            var mini = new UserProfileMini
            {
                firstName  = commentary.UserProfile.FirstName,
                secondName = commentary.UserProfile.SecondName,
                id         = commentary.UserProfile.Id,
                urlPhoto   = commentary.UserProfile.UrlPhoto
            };

            var displayView = new ViewModels.Commentary
            {
                content     = commentary.Content,
                Id          = commentary.Id,
                userProfile = mini,
                dataCreated = commentary.DateCreated,
                userid      = commentary.UserProfile.Id,
                projectid   = commentary.Project.Id
            };

            return(new ObjectResult(displayView));
        }