Ejemplo n.º 1
0
        public ActionResult Edit(int ID)
        {
            var model = new TopicEditViewModel(ID);

            PostQuestionPeriod();
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Edit(Topic topic, int[] periods)
        {
            if (ModelState.IsValid && periods != null)
            {
                QuestionBankDbContext Db = new QuestionBankDbContext();
                Topic konu = Db.Topic.SingleOrDefault(x => x.ID.Equals(topic.ID));
                konu.TopicName = topic.TopicName;
                List <TopicQuestionPeriod> Silinecekler = Db.TopicQuestionPeriod.Where(x => x.TopicID.Equals(topic.ID)).ToList();
                Db.TopicQuestionPeriod.RemoveRange(Silinecekler);
                foreach (var item in periods)
                {
                    Db.TopicQuestionPeriod.Add(new TopicQuestionPeriod()
                    {
                        QuestionPeriodID = item, TopicID = konu.ID
                    });
                }
                Db.SaveChanges();


                var model = new TopicEditViewModel(konu.ID);
                ViewBag.Message = $"<div class='alert alert-success'><strong>Konu Başarıyla güncellendi...</strong>  </div>";
                return(View(model));
            }
            else
            {
                ViewBag.Message = $"<div class='alert alert-danger'><strong>Hata!</strong> Konunun en az bir dönemi olmalı... </div>";
                return(View());
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(TopicEditViewModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect($"/Topics/Edit?topicId={input.Id}&categoryName={input.CategoryName}"));
            }

            if (this.User.IsInRole(GlobalConstants.AdministratorRoleName) ||
                this.User.IsInRole(GlobalConstants.ModeratorRoleName) ||
                this.User.FindFirstValue(ClaimTypes.NameIdentifier) == input.AuthorId)
            {
                await this.topicsService.EditAsync(input);
            }

            return(this.Redirect($"/Topics/Details?topicId={input.Id}"));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Edit(string topicId, string categoryName, string authorId)
        {
            if (this.User.IsInRole(GlobalConstants.AdministratorRoleName) ||
                this.User.IsInRole(GlobalConstants.ModeratorRoleName) ||
                this.User.FindFirstValue(ClaimTypes.NameIdentifier) == authorId)
            {
                var model = await this.topicsService.GetByIdAsInfoViewModelAsync(topicId);

                var viewModel = new TopicEditViewModel()
                {
                    Id           = topicId,
                    CategoryName = categoryName,
                    Title        = model.Title,
                    Content      = model.Content,
                    AuthorId     = authorId,
                };

                return(this.View(viewModel));
            }

            return(this.Redirect($"/Topics/Details?topicId={topicId}"));
        }
Ejemplo n.º 5
0
        public async Task EditAsync(TopicEditViewModel input)
        {
            var topicFromDb = await this.topicRepository
                              .GetByIdWithDeletedAsync(input.Id);

            if (topicFromDb == null)
            {
                throw new ArgumentNullException(
                          string.Format(InvalidTopicIdErrorMessage, input.Id));
            }

            if (input.Title.Length <= TitleMaxLength && input.Title != null && input.Title != topicFromDb.Title)
            {
                topicFromDb.Title = input.Title;
            }

            if (input.Content != null && input.Content.Length >= ContentMinLength && input.Content != topicFromDb.Content)
            {
                topicFromDb.Content = input.Content;
            }

            this.topicRepository.Update(topicFromDb);
            await this.topicRepository.SaveChangesAsync();
        }
Ejemplo n.º 6
0
        public async Task EditAsync_WithIncorrectData_ShouldThrowArgumentNullException()
        {
            // Arrange
            var incorrentInputModelId = "IncorrentId";
            var context         = ApplicationDbContextInMemoryFactory.InitializeContext();
            var topicRepository = new EfDeletableEntityRepository <Topic>(context);
            var userRepository  = new EfDeletableEntityRepository <ApplicationUser>(context);
            var topicsService   = new TopicsService(topicRepository, userRepository);

            var editInputModel = new TopicEditViewModel()
            {
                Id      = incorrentInputModelId,
                Title   = "Edited_TestTitle",
                Content = "Edited_TestContent_TestContent_TestContent_TestContent_TestContent_TestContent",
            };

            // Act

            // Assert
            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await topicsService.EditAsync(editInputModel);
            });
        }
Ejemplo n.º 7
0
        public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit()
        {
            // Arrange
            var context         = ApplicationDbContextInMemoryFactory.InitializeContext();
            var topicRepository = new EfDeletableEntityRepository <Topic>(context);
            var userRepository  = new EfDeletableEntityRepository <ApplicationUser>(context);
            var topicsService   = new TopicsService(topicRepository, userRepository);

            var createInputModel = new CreateTopicInputModel()
            {
                Title   = "TestTitle",
                Content = "TestContent_TestContent_TestContent_TestContent_TestContent_TestContent",
            };

            await topicsService.CreateAsync(createInputModel);

            var topic = topicRepository.All().FirstOrDefault(t => t.Title == "TestTitle");

            var editInputModel = new TopicEditViewModel()
            {
                Id      = topic.Id,
                Title   = "Edited_TestTitle",
                Content = "Edited_TestContent_TestContent_TestContent_TestContent_TestContent_TestContent",
            };

            // Act
            var expectedTopicTitle   = "Edited_TestTitle";
            var expectedTopicContent = "Edited_TestContent_TestContent_TestContent_TestContent_TestContent_TestContent";
            await topicsService.EditAsync(editInputModel);

            // Assert
            topic = await topicRepository.GetByIdWithDeletedAsync(editInputModel.Id);

            Assert.Equal(expectedTopicTitle, topic.Title);
            Assert.Equal(expectedTopicContent, topic.Content);
        }
        // only for the author admins and topic moderators
        public ActionResult Edit(int id)
        {
            TopicEntity topic = topicService.GetEntity(id);
            if (topic == null)
	        {
		        return View("Error");
	        }
            TopicEditViewModel viewModel = new TopicEditViewModel() { Name = topic.Name, Text = topic.Text };
            return View(viewModel);
        }
 public ActionResult Edit(int id, TopicEditViewModel viewModel)
 {
     try
     {
         if (ModelState.IsValid)
         {
             TopicEntity topic = topicService.GetEntity(id);
             topic.Name = viewModel.Name;
             topic.Text = viewModel.Text;
             topicService.Update(topic);
             return RedirectToAction("Index");
         }
     }
     catch (InvalidOperationException e)
     {
         logger.Error(e.Message, e);
         return View("Error");
     }
     return View();
 }
Ejemplo n.º 10
0
        public IActionResult Edit(int?id)
        {
            TopicEditViewModel topicEditViewModel = new TopicEditViewModel();

            return(View("Edit", topicEditViewModel));
        }