示例#1
0
		// GET: Admin

		/// <summary>
		/// Список тем на форуме
		/// </summary>
		/// <param name=""></param>
		public ActionResult TopicsList()
		{
			try
			{
				List<TopicsViewModel> topics = new List<TopicsViewModel>();
				var SectionsBLL = Data.GetSections();
				ViewBag.EmptySection = new string[SectionsBLL.Count()];
				foreach (var s in SectionsBLL)
				{
					var TopicsBLL = Data.GetTopicsForAdmin(s.SectionID);
					if (TopicsBLL.Count() == 0)
					{
						TopicsViewModel topic = new TopicsViewModel();
						topic.SectionID = s.SectionID;
						topic.SectionName = s.SectionName;
						topic.EmptySection = "В разделе ещё нет тем";
						topics.Add(topic);
					}
					else
					{
						foreach (var t in TopicsBLL)
						{
							TopicsViewModel topic = new TopicsViewModel();
							topic.SectionID = s.SectionID;
							topic.SectionName = s.SectionName;
							topic.TopicID = t.TopicID;
							topic.TopicName = t.TopicName;
							topic.AuthorName = t.Name;
							topic.CreateDate = t.CreateDate;
							topic.MessageCount = t.MessageCount;
							var u = Data.LastMessageForAdmin(t.TopicID);
							topic.Name = u.Name;
							topic.SendDate = u.RegistrationDate;
							var messages = Data.GetMessages(t.TopicID);
							foreach (var m in messages)
							{
								if (m.StatusID == 0)
									topic.InvisibleMessages++;
							}
							topics.Add(topic);
						}
					}
				}
				return PartialView(topics);
			}
			catch (ValidationException ex)
			{
				return Content(ex.Message);
			}
		}
示例#2
0
			public ActionResult Index(TopicsViewModel newTopic)
			{
				try
				{
					if (ModelState.IsValid)
					{

						TopicsDTO TopicBLL = new TopicsDTO();
						TopicBLL.SectionID = newTopic.SectionID;
						TopicBLL.TopicName = newTopic.TopicName;
						TopicBLL.TopicText = newTopic.TopicText;
						TopicBLL.UserID = newTopic.UserID;
						Data.CreateTopic(TopicBLL);

						return RedirectToAction("Index");
					}
					else

					{
						var SectionsBLL = Data.GetSections();

						int length = SectionsBLL.Count();
						ViewBag.SectionID = new int[length];
						ViewBag.SectionName = new string[length];

						for (int i = 0; i < length; i++)
						{
							ViewBag.SectionID[i] = SectionsBLL.ElementAt(i).SectionID;
							ViewBag.SectionName[i] = SectionsBLL.ElementAt(i).SectionName;
						}
						if (User.Identity.Name != "")
						{
							var curentUser = Data.GetCurentUser(User.Identity.Name);
							ViewBag.Avatar = curentUser.Avatar;
							ViewBag.Name = curentUser.Name;
							ViewBag.UserID = curentUser.UserID;
						}
						ViewBag.TopicName = newTopic.TopicName;
						ViewBag.TopicText = newTopic.TopicText;

						return View();
					}
				}
				catch (ValidationException ex)
				{
					ModelState.AddModelError("DalError", ex.Message);
					return View(newTopic);
				}
			}