Ejemplo n.º 1
0
		/// <summary>
		/// Создать сообщение
		/// </summary>
		/// <param name="message"></param>
		public bool CreateMessage(MessagesDTO message)
		{
			try
			{
				Messages MessageDAL = new Messages();
				MessageDAL.TopicID = message.TopicID;
				MessageDAL.Text = message.Text;
				MessageDAL.SendDate = DateTime.Now;
				MessageDAL.UserID = message.UserID;
				MessageDAL.StatusID = message.StatusID;

				if (Data.CreateMessage(MessageDAL) == true)
					return true;
				else throw new ValidationException("Ваш запрос не был обработан", "");
			}
			catch (ArgumentException ex)
			{
				throw new ValidationException(ex.Message, ex.ParamName);
			}
		}
Ejemplo n.º 2
0
			public ActionResult Topic(MessagesViewModel newMessage)
			{
				try
				{
					if (ModelState.IsValid)
					{
						MessagesDTO MessageBLL = new MessagesDTO();
						MessageBLL.TopicID = newMessage.TopicID;
						MessageBLL.Text = newMessage.Text;
						MessageBLL.UserID = newMessage.UserID;
						if(User.IsInRole("Administrator"))
                        {
							MessageBLL.StatusID = 1;
						}
						Data.CreateMessage(MessageBLL);

						return RedirectToAction("Topic", new { TopicID = newMessage.TopicID });
					}
					else
					{
						if (User.Identity.Name != "")
						{
							var curentUser = Data.GetCurentUser(User.Identity.Name);
							ViewBag.Avatar = curentUser.Avatar;
							ViewBag.Name = curentUser.Name;
							ViewBag.UserID = curentUser.UserID;
						}
						ViewBag.Text = newMessage.Text;
						ViewBag.TopicID = newMessage.TopicID;						
						return View();
					}
				}
				catch (ValidationException ex)
				{
					ModelState.AddModelError("DalError", ex.Message);
					return View(newMessage);
				}
			}
Ejemplo n.º 3
0
		/// <summary>
		/// Сообщения в теме
		/// </summary>
		/// <param name=""></param>
		public IEnumerable<MessagesDTO> GetMessages(int TopicID)
		{
			try
			{
				List<MessagesDTO> Messages = new List<MessagesDTO>();
				var MessageDAL = Data.GetMessages(TopicID);

				foreach (var m in MessageDAL)
				{
					MessagesDTO message = new MessagesDTO();
					message.MessageID = m.MessageID;
					message.TopicID = m.TopicID;
					message.SendDate = m.SendDate;
					message.Text = m.Text;
					message.StatusID = m.StatusID;
					message.Name = m.Name;
					message.Avatar = m.Avatar;

					Messages.Add(message);
				}
				return Messages;
			}
			catch (ArgumentException ex)
			{
				throw new ValidationException(ex.Message, ex.ParamName);
			}
		}