public void Send(string senderUserId, string targetUserName, string message) { var targetUserId = userRepository.Find(usr => usr.UserName == targetUserName).Id; messageRepository.AddNewMessage( new BaseMessage { Sent = DateTime.UtcNow, Text = message }, new MessageSwitch { SenderUserId = senderUserId, TargetUserId = targetUserId }); }
public ActionResult ShowMessage(string toUser, string messageContent) { if (messageContent.IsNullOrWhiteSpace()) { return(RedirectToAction("ShowMessage")); } //Create new object of Message var newMessage = new Message { MessageContent = messageContent, DateTimeOfMessage = DateTime.Now, FromUserName = User.Identity.Name, ToUserName = toUser }; //Add new Message to database _repo.AddNewMessage(newMessage); //Save changes in database _repo.SaveChanges(); var newMessageNotification = new Notification { NotificationTitle = "Nowa wiadomość!", NotificationContent = "Nowa wiadomość od: " + User.Identity.Name, NotificationDateTime = DateTime.Now, Message = _repo.GetMessageById(newMessage.Id), ApplicationUser = _repo.GetUser(toUser) }; _repo.AddNewNotification(newMessageNotification); //Save changes in database _repo.SaveChanges(); return(RedirectToAction("ShowMessage", "Message", new { username = toUser })); }