예제 #1
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);
				}
			}
예제 #2
0
		/// <summary>
		/// Тема по идентификатору
		/// </summary>
		/// <param name="TopicID"></param>
		public TopicsDTO GetTopicByID(int TopicID)
		{
			try
			{
				TopicsDTO topic = new TopicsDTO();
				var TopicDAL = Data.GetTopicByID(TopicID);

				topic.SectionID = TopicDAL.SectionID;
				topic.TopicID = TopicDAL.TopicID;
				topic.TopicName = TopicDAL.TopicName;
				topic.TopicText = TopicDAL.TopicText;
				topic.Name = TopicDAL.Name;
				topic.CreateDate = TopicDAL.CreateDate;
				topic.Avatar = TopicDAL.Avatar;

				return topic;
			}
			catch (ArgumentException ex)
			{
				throw new ValidationException(ex.Message, ex.ParamName);
			}
		}
예제 #3
0
		/// <summary>
		/// Создать тему
		/// </summary>
		/// <param name="topic"></param>
		public bool CreateTopic(TopicsDTO topic)
		{
			try
			{
				Topics TopicDAL = new Topics();

				TopicDAL.SectionID = topic.SectionID;
				TopicDAL.TopicName = topic.TopicName;
				TopicDAL.TopicText = topic.TopicText;
				TopicDAL.UserID = topic.UserID;
				TopicDAL.CreateDate = DateTime.Now;

				if (Data.CreateTopic(TopicDAL) == true)
					return true;
				else throw new ValidationException("Ваш запрос не был обработан", "");
			}
			catch (ArgumentException ex)
			{
				throw new ValidationException(ex.Message, ex.ParamName);
			}
		}
예제 #4
0
		/// <summary>
		/// Темы в разделе, для администратора
		/// </summary>
		/// <param name="SectionID"></param>
		public IEnumerable<TopicsDTO> GetTopicsForAdmin(int SectionID)
		{
			try
			{
				List<TopicsDTO> Topics = new List<TopicsDTO>();
				var TopicDAL = Data.GetTopicsForAdmin(SectionID);

				foreach (var t in TopicDAL)
				{
					TopicsDTO topic = new TopicsDTO();
					topic.TopicID = t.TopicID;
					topic.SectionID = t.SectionID;
					topic.TopicName = t.TopicName;
					topic.Name = t.Name;
					topic.CreateDate = t.CreateDate;
					topic.MessageCount = t.MessageCount;
					topic.Avatar = t.Avatar;
					Topics.Add(topic);
				}
				return Topics;
			}
			catch (ArgumentException ex)
			{
				throw new ValidationException(ex.Message, ex.ParamName);
			}
		}