public void Create(AddConversationViewModel viewModel) { var conversation = new Conversation { Subject = viewModel.Subject, SenderId = _userManager.GetCurrentUserId(), ReceiverId = viewModel.ReciverId, StartDate = DateTime.Now }; _conversations.Add(conversation); var message = new Message { SenderId = _userManager.GetCurrentUserId(), Content = viewModel.Content.ToSafeHtml(), SendDate = DateTime.Now, ConversationId = conversation.Id }; _messages.Add(message); if (viewModel.Attachments == null || !viewModel.Attachments.Any()) return; foreach (var newFile in viewModel.Attachments.Where(attachment => attachment.HasFile()).Select(attachment => new MessageAttachment { ContentType = attachment.ContentType, Extension = Path.GetExtension(attachment.FileName), FriendlyName = Path.GetFileNameWithoutExtension(attachment.FileName), Data = attachment.InputStream.ConvertToByteArrary(attachment.ContentLength), MessageId = message.Id })) { _attachments.Add(newFile); } }
public void Create(AddConversationViewModel viewModel) { var currentUserId = _userManager.GetCurrentUserId(); var sentOn = DateTime.Now; var conversation = new Conversation { Subject = viewModel.Subject, SenderId = currentUserId, ReceiverId = viewModel.ReciverId, SentOn = sentOn }; _conversations.Add(conversation); var message = new Message { SenderId = currentUserId, Body = viewModel.Body.ToSafeHtml(), SentOn = sentOn, ConversationId = conversation.Id }; _messages.Add(message); }
public virtual async Task<ActionResult> NewMessage(AddConversationViewModel viewModel) { if (!ModelState.IsValid) { return View(viewModel); } _messageService.Create(viewModel); await _unitOfWork.SaveChangesAsync(); return RedirectToAction(MVC.PrivateMessage.OutBox()); }
public virtual async Task<ActionResult> NewMessage() { var viewModel = new AddConversationViewModel { Users = await _userManager.GetAsSelectListItem() }; return View(viewModel); }