public NewMailView(NewMailViewModel viewModel) { InitializeComponent(); Loaded += (s, e) => { this.DataContext = viewModel; }; }
public async Task <IActionResult> NewMail(string id) { var toUser = await _userManager.FindByIdAsync(id); var model = new NewMailViewModel(); if (toUser != null) { model.UserName = toUser.UserName; } return(View(model)); }
public async Task <IActionResult> NewMail(NewMailViewModel model) { if (ModelState.IsValid) { var toUser = await _userManager.FindByNameAsync(model.UserName); if (toUser == null) { ModelState.AddModelError(string.Empty, "Nie ma takiego gracza."); } else { var user = await _userManager.GetUserAsync(User); var receivedMail = new Mail() { FromId = user.Id, ToId = toUser.Id, Type = MailType.Received, Title = model.Title, Content = model.Content, Status = MailStatus.New }; var sentMail = new Mail() { FromId = user.Id, ToId = toUser.Id, Type = MailType.Sent, Title = model.Title, Content = model.Content, Status = MailStatus.New }; _mailRepository.Add(receivedMail); _mailRepository.Add(sentMail); } } return(View(model)); }