Ejemplo n.º 1
0
        public ActionResult Topic(int id, int?page)
        {
            BllTopic topic = GetTopic(id, page);

            ViewBag.IsMyTopic = IsMyTopic(topic.Id);
            return(View(topic.ToTopicDitailsModel()));
        }
Ejemplo n.º 2
0
        public ActionResult _Comments(int id, int?page)
        {
            BllTopic topic = GetTopic(id, page);

            ViewBag.IsMyTopic = IsMyTopic(topic.Id);
            return(PartialView(topic.Comments
                               .Select(c => c.ToCommentModel())));
        }
Ejemplo n.º 3
0
        private BllTopic GetTopic(int id, int?page)
        {
            BllTopic topic = topicService.GetTopic(id);

            topic.Comments = this.GetItemsOnPage(
                topic.Comments.OrderBy(c => c.Date), page, COMMENTS_PER_PAGE);

            return(topic);
        }
Ejemplo n.º 4
0
 public static CreateEditTopicModel ToCreateEditTopicModel(this BllTopic bllTopic)
 {
     return(new CreateEditTopicModel
     {
         Id = bllTopic.Id,
         //AuthorId = bllTopic.Author.Id,
         Title = bllTopic.Title,
         Text = bllTopic.Text,
         Section = bllTopic.Section.Id.ToString(),
     });
 }
Ejemplo n.º 5
0
 public ActionResult CreateTopic(CreateEditTopicModel topic)
 {
     if (ModelState.IsValid)
     {
         BllTopic bllTopic = topic.ToBllTopic();
         bllTopic.Author = userService.GetUser(User.Identity.Name);
         topicService.AddTopic(bllTopic);
         return(RedirectToAction("Topics"));
     }
     return(View(topic));
 }
Ejemplo n.º 6
0
        public ActionResult GetRawTopic()
        {
            BllTopic topic = topicService.GetRawTopic();

            if (topic != null)
            {
                return(RedirectToAction("EditTopic", new { id = topic.Id }));
            }
            else
            {
                return(View("Info", (object)"All topics are processed."));
            }
        }
Ejemplo n.º 7
0
 private ActionResult ChangeTopicState(CreateEditTopicModel topic, StatusEnum status)
 {
     if (ModelState.IsValid)
     {
         BllTopic bllTopic = topic.ToBllTopic();
         bllTopic.Status = new BllStatus {
             Id = (int)status
         };
         topicService.UpdateTopic(bllTopic);
         return(RedirectToAction("Topic", "Home", new { id = topic.Id }));
     }
     return(View("EditTopic", topic));
 }
Ejemplo n.º 8
0
 public static TopicDitailsModel ToTopicDitailsModel(this BllTopic bllTopic)
 {
     return(new TopicDitailsModel
     {
         Id = bllTopic.Id,
         Title = bllTopic.Title,
         Author = bllTopic.Author?.ToShortUserModel(),
         Date = bllTopic.Date,
         IsAnswered = bllTopic.IsAnswered,
         Text = bllTopic.Text,
         Comments = bllTopic.Comments.Select(c => c.ToCommentModel()),
     });
 }
Ejemplo n.º 9
0
 public static TopicListModel ToTopicListModel(this BllTopic bllTopic)
 {
     return(new TopicListModel
     {
         Id = bllTopic.Id,
         Title = bllTopic.Title,
         AuthorLogin = bllTopic.Author?.Login,
         Date = bllTopic.Date,
         IsAnswered = bllTopic.IsAnswered,
         SectionName = bllTopic.Section.Name,
         SectionId = bllTopic.Section.Id,
         Status = bllTopic.Status.Name,
     });
 }
Ejemplo n.º 10
0
        public ActionResult EditTopic(int id)
        {
            BllTopic bllTopic = topicService.GetTopic(id);

            bllTopic.Status = new BllStatus {
                Id = (int)StatusEnum.Processed
            };
            topicService.UpdateTopic(bllTopic);
            CreateEditTopicModel topic = bllTopic.ToCreateEditTopicModel();

            topic.Sections = topicService.GetAllSections()
                             .Select(s => new SelectListItem {
                Text = s.Name, Value = s.Id.ToString()
            });
            return(View(topic));
        }
Ejemplo n.º 11
0
 public void AddTopic(BllTopic topic)
 {
     topic.Date   = DateTime.Now;
     topic.Status = new BllStatus()
     {
         Id = (int)StatusEnum.Raw
     };
     try
     {
         topicRepository.Add(topic.ToDalTopic());
     }
     catch (InvalidOperationException e)
     {
         logger.Warn(e.Message);
         throw;
     }
 }
Ejemplo n.º 12
0
        public void UpdateTopic(BllTopic topic)
        {
            DalTopic dalTopic = topicRepository.First(t => t.Id == topic.Id);

            dalTopic.Title      = topic.Title;
            dalTopic.Text       = topic.Text;
            dalTopic.Status.Id  = topic.Status.Id;
            dalTopic.Section.Id = topic.Section.Id;
            try
            {
                topicRepository.Update(dalTopic);
            }
            catch (InvalidOperationException e)
            {
                logger.Warn(e.Message);
                throw;
            }
        }
Ejemplo n.º 13
0
 public static DalTopic ToDalTopic(this BllTopic bllTopic)
 {
     return(new DalTopic
     {
         Id = bllTopic.Id,
         Title = bllTopic.Title,
         Text = bllTopic.Text,
         Date = bllTopic.Date,
         IsAnswered = bllTopic.IsAnswered,
         Section = bllTopic.Section.ToDalSection(),
         Author = new DalUser {
             Id = bllTopic.Author.Id
         },
         Status = new DalStatus {
             Id = bllTopic.Status.Id
         },
     });
 }
Ejemplo n.º 14
0
        private void AddTopic(string[] args)
        {
            if (!IsAutorize())
            {
                PrintError(NotAutorizedError);
                return;
            }

            Sections(null);

            var topic = new BllTopic
            {
                Section = new BllSection {
                    Id = ReadInt("Section")
                },
                Title  = ReadString("Title"),
                Text   = ReadString("Text"),
                Author = me,
            };

            topicService.AddTopic(topic);

            MyTopics(null);
        }