Example #1
0
        public JsonResult AddComment()
        {
            CommentAddViewModel vm = new CommentAddViewModel();
            string text            = RequestUtils.GetFormText(Request, "text");
            int    contentID       = RequestUtils.GetFormInt(Request, "objectid");

            if (_profileService.CurrentProfile != null && !string.IsNullOrEmpty(text) && contentID > 0)
            {
                {
                    var comment = new Comment
                    {
                        ProfileID    = _profileService.CurrentProfile.ID,
                        Text         = text,
                        CreateDate   = DateTime.Now,
                        ObjectID     = contentID,
                        ObjectType   = "content",
                        ProfileName  = _profileService.CurrentProfile.Name,
                        ProfileImage = _profileService.CurrentProfile.Image
                    };
                    comment.ID = _contentRepository.AddComment(comment);
                    vm.Status  = "success";

                    var content = _contentRepository.GetContent(comment.ObjectID);
                    if (content != null)
                    {
                        vm.CommentCount = content.CommentCount;
                    }
                    //     vm.Comment = comment;
                    // Формирование даты для вывода.
                    //vm.Date = content.CreateDate.ToString("dd MMMM yyyy") + " в " + content.CreateDate.ToString("HH:mm");

                    vm.Comment = new CommentViewModel(comment);
                }
            }
            return(Json(vm));
        }
Example #2
0
        public JsonResult Add()
        {
            ContentAddViewModel vm = new ContentAddViewModel();

            vm.Status = "error";
            // vm.WebRootPath = _environment.WebRootPath;
            string title = RequestUtils.GetFormText(Request, "title");
            string text  = RequestUtils.GetFormText(Request, "text");
            string token = RequestUtils.GetFormText(Request, "token");

            // Валидация.
            if (string.IsNullOrEmpty(title))
            {
                vm.ErrorTitle = _localizationService.GetValue("Input post title");
            }
            if (string.IsNullOrEmpty(text))
            {
                vm.ErrorText = _localizationService.GetValue("Input post text");
            }
            if (!string.IsNullOrEmpty(token))
            {
                _profileService.GetCurrentAccountByToken(token);
            }

            /* var account = _accountRepository.GetAccountByEmail(User.Identity.Name);
             * if (account == null)
             * {
             *   //return 404;
             *   vm.Result = "account == null";
             * }*/
            if (string.IsNullOrEmpty(vm.ErrorTitle) && string.IsNullOrEmpty(vm.ErrorText) && _profileService.CurrentProfile != null)
            {
                var content = new Content
                {
                    ProfileID   = _profileService.CurrentProfile.ID,// Указываем профиль из запроса
                    Title       = title,
                    Text        = text,
                    CreateDate  = DateTime.Now,
                    UpdateDate  = DateTime.Now,
                    PublishDate = DateTime.Now
                };
                content.ID = _contentRepository.AddContent(content);

                vm.Status = "success";
                vm.Title  = content.Title;
                vm.Text   = content.Text;
                // Формирование даты для вывода.
                vm.Date = content.CreateDate.ToString("dd MMMM yyyy") + " в " + content.CreateDate.ToString("HH:mm");
                string image = "";
                var    files = _fileStorageService.SaveFiles(_environment.WebRootPath, Request.Form.Files, content.ID, "content");
                if (files != null && files.Count > 0)
                {
                    image         = files[0].Filename;
                    content.Image = image;
                    _contentRepository.UpdateContentImage(content);
                }
                // TODO для отрисовки ссылка на картинку
                vm.ImageLink = LinkBuilder.Image(image, true);
            }
            else
            {
            }

            return(Json(vm));
        }