Ejemplo n.º 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));
        }
Ejemplo n.º 2
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));
        }