示例#1
0
        public ActionResult Edit(int id, EditTopicViewModel model)
        {
            try
            {
                var repository = new TopicRepository(context);
                if (model.Name != model.NombreAnterior)
                {
                    var existeNombre = repository.Query(x => x.Name == model.Name && x.Id != model.Id).Count > 0;
                    if (existeNombre)
                    {
                        ModelState.AddModelError("Name", "El nombre ya está ocupado por otro tópico.");
                        return(View(model));
                    }
                }
                else
                {
                    ModelState.Remove("Nombre");
                }

                if (ModelState.IsValid)
                {
                    var topic = MapperHelper.Map <Topic>(model);
                    repository.Update(topic);
                    context.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
 public ActionResult Edit([Bind(Include = "ID,Subject,Created,UsersID,StatusID")] Topic topic)
 {
     if (ModelState.IsValid)
     {
         repTopic.Update(topic);
         return(RedirectToAction("Index"));
     }
     ViewBag.StatusID = new SelectList(db.Status, "Id", "Name", topic.StatusID);
     ViewBag.UsersID  = new SelectList(db.Users, "Id", "UserName", topic.UserID);
     return(View(topic));
 }
示例#3
0
 public TopicDetailModel Save(TopicDetailModel model)
 {
     if (model.Id == Guid.Empty)
     {
         return(repository.Add(model));
     }
     else
     {
         repository.Update(model);
         return(model);
     }
 }
示例#4
0
        public void TestEntityUpdate()
        {
            var topic = new Topic("Nome teste");

            var mockTeste = new Mock <IUpdateDB <Topic> >();

            var topicRepository = new TopicRepository(mockTeste.Object);

            topicRepository.Update(topic);

            mockTeste.Verify(x => x.UpdateRegister(It.IsAny <Topic>()));
        }
示例#5
0
        public async Task <TopicDto> UpdateTopic(TopicDto topicDto)
        {
            if (topicDto.TopicName.Contains(","))
            {
                throw new FormInvalidException("", "Topic name cannot contain ','");
            }

            var topic = await _repository.GetById(topicDto.Id);

            topic = _mapper.Map(topicDto, topic);
            await _repository.Update(topic);

            return(topicDto);
        }
示例#6
0
 //Disapprove topic
 public bool Disapprove(int topicID)
 {
     try
     {
         Topic topic = this.TopicRepository.GetByID(topicID);
         topic.IsApproved = false;
         TopicRepository.Update(topic);
         this.Save();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
        public IActionResult  FollowTopic(int topicID)
        {
            int memberID = int.Parse(HttpContext.Request.Cookies["ID"]);

            Member member = _memberRepository.Get(a => a.ID == memberID);
            Topic  topic  = _topicRepository.Get(a => a.ID == topicID);

            topic.MemberFollowedTopics.Add(new MemberFollowedTopic {
                Member = member, Topic = topic
            });

            _topicRepository.Update(topic);

            return(RedirectToAction(nameof(Index)));
        }
示例#8
0
        public ActionResult Edit(TopicModel topic, Guid topicId)
        {
            //Guid.TryParse(topicId, out Guid topicIdGuid);

            //TopicModel topic = _topicRepository.GetById(topicIdGuid);

            topic.TopicId = topicId;

            if (topic != null)
            {
                _topicRepository.Update(topic);
                _topicRepository.Save();

                return(RedirectToAction("Index", "Home"));
            }

            return(RedirectToAction("Index"));
        }
示例#9
0
        public IHttpActionResult Put(int topic_id, [FromBody] BlogTopic blogTopic)
        {
            if (!IsUserAdmin())
            {
                // If user isn't admin
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Unauthorized)));
            }

            if (!ModelState.IsValid)
            {
                // IF Model State is invalid
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState)));
            }

            ITopicRepository topicRepository = new TopicRepository();

            // Get Topic from Db
            try
            {
                var dbBlogTopic = topicRepository.Get(topic_id);
                if (dbBlogTopic != null)
                {
                    // Update the value in db
                    dbBlogTopic.Name = blogTopic.Name;
                    topicRepository.Update(dbBlogTopic);
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.OK)));
                }
                else
                {
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotFound, "Topic doesn't exist")));
                }
            }
            catch
            {
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, "Failed to update topic name")));
            }
        }