public ActionResult Edit(int id) { var result = _repository.FindById(id); if (result == null) { return(HttpNotFound()); } var newResult = Mapper.Map <News, NewsDtoForUpdate>(result); var categoriesRepository = new GlobalRepository <NewsCategory>(); var categories = categoriesRepository.FindAll(); var newsForm = new NewsForm { Title = newResult.Title, Content = newResult.Content, Image = newResult.Image, NewsCategoryId = newResult.NewsCategoryId, NewsCategory = newResult.NewsCategory, ModifiedBy = newResult.ModifiedBy, ModifiedOn = newResult.ModifiedOn, Categories = GetAllCategories(categories), ViewMode = Enums.ViewMode.Edit }; return(View(newsForm)); }
public News Map(NewsForm form) { var news = new News(); news.Title = form.Title; news.Description = form.Description; news.Date = DateTime.Now; return news; }
public News Map(NewsForm form) { var news = new News(); news.Title = form.Title; news.Description = form.Description; news.Date = DateTime.Now; return(news); }
public ActionResult New() { var categoriesRepository = new GlobalRepository <NewsCategory>(); var categories = categoriesRepository.FindAll(); var newsForm = new NewsForm { Categories = GetAllCategories(categories), ViewMode = Enums.ViewMode.Add }; return(View("Edit", newsForm)); }
public ActionResult Save(NewsForm news) { if (!ModelState.IsValid) { return(View("Edit", news)); } if (news.ViewMode == Enums.ViewMode.Add) { // New News var newsModel = Mapper.Map <NewsForm, News>(news); if (User.IsInRole("Administrator") || User.IsInRole("Editor")) { newsModel.Status = "Approved"; } else { newsModel.Status = "Pending"; } newsModel.CreatedBy = Guid.Parse(User.Identity.GetUserId()); newsModel.CreatedOn = DateTime.Now; newsModel.UserId = newsModel.CreatedBy.ToString(); newsModel.ModifiedOn = newsModel.CreatedOn; _repository.Add(newsModel); } else { // Update News var newsInDb = _repository.FindById(news.Id); // Copy from VM newsInDb.Title = news.Title; newsInDb.Image = news.Image; newsInDb.Content = news.Content; newsInDb.NewsCategoryId = news.NewsCategoryId; newsInDb.UserId = User.Identity.GetUserId(); newsInDb.ModifiedOn = DateTime.Now; _repository.SaveChanges(); } return(RedirectToAction("Index", "News")); }
public ActionResult Show(int id) { var result = _repository.Find(n => n.Id == id); var news = result.FirstOrDefault(); ViewBag.showButtons = false; if (User.IsInRole("Editor") || User.IsInRole("Administrator")) { ViewBag.showButtons = true; } ViewBag.isAdmin = User.IsInRole("Administrator"); ViewBag.currentUser = User.Identity.GetUserId(); var newResult = Mapper.Map <News, NewsDtoForUpdate>(news); var commentsRepository = new GlobalRepository <Comment>(); var comments = commentsRepository.Find(c => c.NewsId == news.Id).OrderByDescending(c => c.CreatedOn); var newsForm = new NewsForm { Id = news.Id, Title = news.Title, Content = news.Content, Image = news.Image, NewsCategoryId = news.NewsCategoryId, NewsCategory = news.NewsCategory, ModifiedBy = Guid.Parse(news.UserId), User = news.User, ModifiedOn = news.ModifiedOn, Comments = comments.ToList() }; return(View(newsForm)); }
public void Editnew([FromUri] int id, [FromBody] NewsForm form) { var map = _newsMapper.Map(id, form); _newsRepository.UpdateNews(map); }
public void Forminfo([FromBody] NewsForm form) { var map = _newsMapper.Map(form); _newsRepository.InsertNews(map); }
public void WhenINavigateToMainPage(string item) { var newsF = new NewsForm(); newsF.sideMenu.NavigateToMenuItem(item); }
public void WhenIClickProfileMenu() { var newsF = new NewsForm(); newsF.ClickProfileMenuBtn(); }
private void NewsBtn_Click(object sender, EventArgs e) { NewsForm.LoadNews(); }
public void VkApiTesting() { Log.Step("Navigate to vk.com"); var loginF = new LoginForm(); Log.Step("Login"); loginF.Login(_username, _password); Log.Step("Navigate to 'My Page'"); var newsF = new NewsForm(); newsF.ClickMyPageBtn(); Log.Step("Using the API request, create an post with randomly generated text on the wall and get the record id from the response"); var vkApiUtils = new VkApiUtils(); var messagePost = RandomUtils.RandomString(LenghtMessage); var idPost = vkApiUtils.CreateWallPost(_userId, MethodEnum.WALL_POST.GetStringMapping(), _token, messagePost); var mainF = new MainForm(); Log.Step("Not updating the page, check was an post on the wall with the right text from the right user"); Assert.IsTrue(mainF.IsWallPostMessage(messagePost), "This post doesn't exist on the wall"); Assert.IsTrue(mainF.IsWallPostUser(_userId, messagePost), "This user not sent this post to the wall"); Log.Step("Edit the post through the API request - change the text and add (load) any picture."); var messageEditPost = RandomUtils.RandomString(LenghtMessage); var photoInfo = vkApiUtils.AddPhotoWithMessage(_userId, idPost, MethodEnum.PHOTOS_SAVE_WALL_PHOTO.GetStringMapping(), _token, _pathToFolderResources + _photoOriginalName, messageEditPost); Log.Step(@"Without updating the page, make sure that the text of the message has changed and the uploaded image has been added(make sure that the pictures are the same)"); Assert.IsTrue(mainF.IsWallPostMessage(messageEditPost), "This post didn't edited on the wall"); var downloadedFileName = mainF.DownloadFile(_pathToFolderResources, photoInfo["photoId"]); var similarityImages = mainF.ComparePhoto(_pathToFolderResources, _photoOriginalName, downloadedFileName); Assert.IsTrue(similarityImages < IPuzzle.LowSimilarityThreshold, "Images don't match"); Log.Step("Using the API request, add a comment to the post with random text"); var messageComment = RandomUtils.RandomString(LenghtMessage); vkApiUtils.ExecuteMessageActionWall(_userId, idPost, MethodEnum.WALL_CREATE_COMMENT.GetStringMapping(), _token, messageComment); Log.Step("Not updating the page, it's necessary that a comment from the right user is added to the correct post"); Assert.IsTrue(mainF.IsCommentWallPost(messageEditPost), "This post not present on the wall"); Assert.IsTrue(mainF.IsCommentWallPostUser(_userId, messageComment), "This user not sent this post to the wall"); Assert.IsTrue(mainF.IsCommentWallPostMesage(messageComment), "This comment not present on the wall"); Log.Step("Through UI, add 'Like' for the record."); mainF.AddLikeWallPost(messageEditPost); Log.Step("Through the request to the API, make sure that the 'Like' was sent from the right user"); Assert.IsTrue(vkApiUtils.IsUserLikePost(_userId, idPost, MethodEnum.LIKES_ISLIKED.GetStringMapping(), "post", _token), "No like from this user"); Log.Step("Via the API request, delete the created record"); vkApiUtils.DeleteWallPost(_userId, idPost, MethodEnum.WALL_DELETE.GetStringMapping(), _token); Log.Step("Not updating the page, it's necessary to make sure that the entry is deleted"); Assert.IsTrue(mainF.IsDeletedWallPost(), "Post wasn't deleted from the wall"); vkApiUtils.DeletePhotoFromSite(MethodEnum.PHOTOS_DELETE.GetStringMapping(), _userId, photoInfo["photoPid"], _token); mainF.DeletePhotoDownloadedFromVk(_pathToFolderResources, downloadedFileName); }