public ActionResult Edit() { Content content = new Content(); ContentAddViewModel contentAddViewModel = new ContentAddViewModel { Content = content }; var categories = _categoryRepository.AllCategories; contentAddViewModel.CategoryList = new List <SelectListItem>(); foreach (var category in categories) { contentAddViewModel.CategoryList.Add(new SelectListItem() { Text = category.Name, Value = category.CategoryId.ToString() }); } var contents = _contentRepository.AllContents; contentAddViewModel.Contents = contents; contentAddViewModel.Total = _contentRepository.GetTotalForAllContentItems(contents); return(View(contentAddViewModel)); }
public ActionResult Edit(ContentAddViewModel contentListItem) { _contentRepository.AddContent(contentListItem.Content); return(RedirectToAction("Edit")); }
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)); }