Пример #1
0
        public NewMailView(NewMailViewModel viewModel)
        {
            InitializeComponent();

            Loaded += (s, e) =>
            {
                this.DataContext = viewModel;
            };
        }
Пример #2
0
        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));
        }
Пример #3
0
        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));
        }