public async Task <IActionResult> Messages(string message, string toid) { BookThruUser u = _context.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault(); Message m = new Message { Content = message, FromId = u.Id, ToId = toid, Sent = DateTime.Now.Date }; _context.Message.Add(m); await _context.SaveChangesAsync(); await _emailSender.SendEmailAsync(toid, "New Message", $"You have a mesasge from " + User.Identity.Name); ViewBag.Email = toid; BookThruUser user = _context.Users.Where(x => x.Id == toid).FirstOrDefault(); ViewBag.Name = _context.UserInfo.Where(x => x.Id == user.Id).FirstOrDefault().FirstName; AddContact(toid, _context.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault().Id); AddContact(_context.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault().Id, toid); var lists = await _context.Message.Where(x => (x.FromId.Equals(u.Id) && x.ToId.Equals(toid)) || x.ToId.Equals(u.Id) && x.FromId.Equals(toid)).ToListAsync(); return(View(lists)); //return View(await _context.Book.Where(x=>x.Uploaded> DateTime.Now.Date).ToListAsync()); }
public async Task <IActionResult> ChangeRole(string Id) { var user = await _context.Users.FindAsync(Id); var roles = await _userManager.GetRolesAsync(user); await _userManager.RemoveFromRolesAsync(user, roles); if (roles.Contains("Admin")) { await _userManager.RemoveFromRolesAsync(user, roles); await _userManager.AddToRoleAsync(user, "User"); } else { await _userManager.RemoveFromRolesAsync(user, roles); await _userManager.AddToRoleAsync(user, "Admin"); } await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> OnPostAsync() { //if (!ModelState.IsValid) //{ // return Page(); //} var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } var phoneNumber = await _userManager.GetPhoneNumberAsync(user); if (Input.PhoneNumber != phoneNumber) { var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber); if (!setPhoneResult.Succeeded) { var userId = await _userManager.GetUserIdAsync(user); throw new InvalidOperationException($"Unexpected error occurred setting phone number for user with ID '{userId}'."); } } var userInfo = _context.UserInfo.Where(x => x.Id == user.Id).FirstOrDefault(); if (userInfo != null) { //if (this.Request.Form.Files.Count < 2) // throw new Exception("Please include a image file to upload."); IFormFile imageFile = null; try { var file = this.Request.Form.Files[0]; if (file.FileName.Contains(".jpeg") || file.FileName.Contains(".jpg") || file.FileName.Contains(".png")) { imageFile = this.Request.Form.Files[0]; } } catch (Exception) { } Random rnd = new Random(); if (Input.UserInfo.PhoneNumber != userInfo.PhoneNumber || Input.UserInfo.FirstName != userInfo.FirstName || Input.UserInfo.LastName != userInfo.LastName) { userInfo.FirstName = Input.UserInfo.FirstName; userInfo.LastName = Input.UserInfo.LastName; userInfo.PhoneNumber = Input.UserInfo.PhoneNumber; if (imageFile != null) { userInfo.PictureUrl = rnd.Next(99999999).ToString() + "." + imageFile.FileName; await UploadFileAsync(imageFile.OpenReadStream(), Input.UserInfo.PictureUrl); } _context.UserInfo.Update(userInfo); await _context.SaveChangesAsync(); } } else { //if (this.Request.Form.Files.Count < 2) // throw new Exception("Please include a image file to upload."); IFormFile imageFile = null; IFormFile resumeFile = null; try { imageFile = this.Request.Form.Files[0]; resumeFile = this.Request.Form.Files[1]; } catch (Exception) { } //Input.JobSeeker.PictureUrl = ""; //Input.JobSeeker.ResumeUrl = ""; Random rnd = new Random(); if (imageFile != null) { Input.UserInfo.PictureUrl = rnd.Next(99999999).ToString() + "." + imageFile.FileName; await UploadFileAsync(imageFile.OpenReadStream(), Input.UserInfo.PictureUrl); } UserInfo jobSeekerNew = new UserInfo { Id = user.Id, FirstName = Input.UserInfo.FirstName, LastName = Input.UserInfo.LastName, PhoneNumber = Input.UserInfo.PhoneNumber, PictureUrl = Input.UserInfo.PictureUrl, }; var jobSeekerrId = await _context.UserInfo.AddAsync(jobSeekerNew); _context.SaveChangesAsync(); if (jobSeekerrId == null) { var userId = await _userManager.GetUserIdAsync(user); throw new InvalidOperationException($"Unexpected error occurred setting Recruiter with ID '{userId}'."); } } await _signInManager.RefreshSignInAsync(user); StatusMessage = "Your profile has been updated"; return(RedirectToPage()); }