public async Task <IActionResult> Create([Bind("Id,Sender,Receiver,Subject,Message,DateTime")] MailBoxDto model) { if (ModelState.IsValid) { var userid = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value; var mailBox = _mapper.Map <MailBox>(model); mailBox.DateTime = DateTime.Now; var user = HttpContext.User.FindFirst(ClaimTypes.Name).Value; mailBox.UserId = userid; mailBox.Sender = user; mailBox.CreatedAt = DateTime.Now; await _service.AddMailAsync(mailBox); await _emailSender.SendEmailAsync(mailBox.Receiver, mailBox.Subject, mailBox.Message); return(RedirectToAction(nameof(Index))); } return(View(model)); }