public ActionResult newTopic(int id) { Message m = new Message(); m.BoardID = id; return View(m); }
public ActionResult newTopic(Message message) { if (ModelState.IsValid) { message.Created = DateTime.Now; db.Messages.Add(message); db.SaveChanges(); return RedirectToAction("showBoard", new {id = message.BoardID}); } return View(message); }
public HttpResponseMessage PostCreate(SendMessageModel messageModel, string sessionKey) { HttpResponseMessage responseMessage = this.PerformOperationAndHandleExceptions( () => { ForumContext context = new ForumContext(); using (context) { User currentUser = context.Users.FirstOrDefault(usr => usr.SessionKey == sessionKey); if (currentUser == null) { throw new ArgumentException("Invalid user data!"); } User reciever = context.Users.FirstOrDefault(usr => usr.Username == messageModel.ToUser); if (reciever == null) { throw new ArgumentException("Cannot send message to not registred users!"); } var message = new Message { Sender = currentUser, Reciever = reciever, Content = messageModel.Content, CreationDate = DateTime.Now }; context.Messages.Add(message); context.SaveChanges(); HttpResponseMessage response = this.Request.CreateResponse(HttpStatusCode.Created, message); return response; } }); return responseMessage; }