コード例 #1
0
        public async Task <IHttpActionResult> Index(string iduser)
        {
            var publicacoes = await GetPost.Publicacoes(iduser);

            var retorno = new PostBindModel().Convert(publicacoes);

            return(Ok(retorno));
        }
コード例 #2
0
ファイル: PostController.cs プロジェクト: hanoitown/vnsf
        public ActionResult Create()
        {
            var vm = new PostBindModel
            {
                PublishDate = DateTime.Today
            };
            ViewData["Categories"] = _uow.Categories.AllIncluding(c => c.Classification).Where(c => c.Classification.Name.Contains("Posts"))
                                            .ToSelectList(c => c.Id.ToString(), c => c.Name.ToString(), string.Empty);

            return View(vm);
        }
コード例 #3
0
        public ProjectReturnBindingModel Convert(Project project)
        {
            if (project != null)
            {
                var laboratory = new LaboratoryReturnBindingModels()
                {
                    Id        = project.Laboratory.Id,
                    Descricao = project.Laboratory.Descricao
                };

                var projeto = new ProjectReturnBindingModel()
                {
                    Id          = project.Id,
                    Descricao   = project.Descricao,
                    Titulo      = project.Titulo,
                    DataCriacao = project.DataCriacao,
                };

                var membros = new List <UserSimple>();

                var posts = new List <PostBindModel>();

                foreach (User u in project.Laboratory.Users)
                {
                    UserSimple simpleUser = new UserSimple();
                    simpleUser.Id    = u.Id;
                    simpleUser.Nome  = u.Nome;
                    simpleUser.Email = u.Email;
                    membros.Add(simpleUser);
                }

                foreach (Core.Models.Post p in project.Posts)
                {
                    PostBindModel post = new PostBindModel()
                    {
                        Id               = p.Id.ToString(),
                        Mensagem         = p.Mensagem,
                        Autor            = p.Autor.Nome,
                        UrlDocumento     = p.UrlDocumento,
                        DataDePublicacao = p.DataPublicacao
                    };
                    posts.Add(post);
                }

                posts.Reverse();
                projeto.Posts      = posts;
                projeto.Membros    = membros;
                projeto.laboratory = laboratory;
                return(projeto);
            }
            return(null);
        }
コード例 #4
0
        public IActionResult Posts(PostBindModel model)
        {
            if (null == model || !model.PostId.HasValue)
            {
                return(RedirectToAction("Index"));
            }

            //
            var viewModel = this._viewProjectionFactory.GetViewProjection <PostBindModel, PostViewModel>(model);

            Set();
            return(View("PostDetails", viewModel));
        }
コード例 #5
0
ファイル: PostController.cs プロジェクト: hanoitown/vnsf
        public ActionResult Create(PostBindModel form)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var category = _uow.Categories.FindById(form.CategoryId);
                    _uow.Posts.Add(Post.New(form.Title, form.Abstract, form.Content, form.PublishDate, category));
                    _uow.Save();

                    return RedirectToAction<PostController>(p => p.Index()).WithSuccess("Created");
                }

                return RedirectToAction<PostController>(p => p.Index()).WithError("Invalid data");
            }
            catch
            {
                return View();
            }
        }
コード例 #6
0
        public IActionResult Posts(PostBindModel model)
        {
            if (null == model || model.PostId.IsNullOrWhitespace() || model.PostPutSortTime.IsNullOrWhitespace())
            {
                return(View("Index", null));
            }

            //
            var viewModel = this._viewProjectionFactory.GetViewProjection <PostBindModel, PostViewModel>(model);


            // 如果查询到的数据不为空,那么拼接出全路径
            if (null != viewModel.PostInfo)
            {
                viewModel.PostInfo.post_path = this._hostingEnvironment.WebRootPath.WinLinuxPathSwitchCombine(viewModel.PostInfo.post_path);
                if (!System.IO.File.Exists(viewModel.PostInfo.post_path))
                {
                    throw new System.Exception($"未找到文件!{viewModel.PostInfo.post_path}");
                }
            }

            Set();
            return(View("PostDetails", viewModel));
        }
コード例 #7
0
ファイル: PostController.cs プロジェクト: hanoitown/vnsf
        public ActionResult Edit(Guid id, PostBindModel form)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var cat = _uow.Categories.FindById(form.CategoryId);
                    var post = _uow.Posts.FindById(form.Id);

                    post.Title = form.Title;
                    post.Abstract = form.Abstract;
                    post.Content = form.Content;
                    post.PublishDate = form.PublishDate;
                    post.Category = cat;

                    _uow.Save();

                    return RedirectToAction<PostController>(p => p.Index()).WithSuccess("Updated");
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }