public IActionResult Eliminar(int?id) { SQLController sQL = new SQLController(); sQL.EliminarNotificacion(id); var idusuario = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var datos = _db.Users.Where(u => u.Id == idusuario).FirstOrDefault(); var cantidaddenotificaciones = _db.Notificaciones.Where(n => n.ID_Usuario == datos.ID_Usuario).Where(n => n.Estado == "Sin Leer").Count(); Alertas.cantidaddenotificacion = cantidaddenotificaciones; return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Index(IndexViewModel model, string fotoactual, IFormFile pic) { if (!ModelState.IsValid) { return(View(model)); } string perfil = ""; var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } var usuarioDb = _db.Users.Where(u => u.Email.Equals(model.Email)).FirstOrDefault(); if (pic != null) { var ruta = Path.GetFileName(pic.FileName); SQLController SQL = new SQLController(); string[] extencion = ruta.Split('.'); var filename = Path.Combine(he.WebRootPath + "/FotosPerfil", "perfil-" + model.Email + "." + extencion[extencion.Length - 1]); if (System.IO.File.Exists(filename)) { try { System.IO.File.Delete(filename); } catch (IOException x) { return(View("Error")); } } pic.CopyTo(new FileStream(filename, FileMode.Create)); perfil = Path.GetFileName(filename); //he.IsStaging(); } usuarioDb.Nombre = model.Nombre; usuarioDb.Apellido = model.Apellido; usuarioDb.Tipo_Usuario = model.Tipo_Usuario; usuarioDb.Telefono = model.Telefono; usuarioDb.Imagen = perfil; if (pic != null) { usuarioDb.Imagen = perfil; Alertas.cambiodefoto = "Su nueva foto de perfil se mostrara en minutos"; } else { usuarioDb.Imagen = fotoactual; } await _db.SaveChangesAsync(); StatusMessage = "Your profile has been updated"; return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Register(RegisterViewModel model, IFormFile foto, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { string picture = ""; if (foto != null) { string ruta = Path.GetFileName(foto.FileName); string[] extencion = ruta.Split('.'); string filename = Path.Combine(he.WebRootPath + "/FotosPerfil", "perfil-" + model.Email + "." + extencion[extencion.Length - 1]); if (System.IO.File.Exists(filename)) { System.IO.File.Delete(filename); } foto.CopyTo(new FileStream(filename, FileMode.Create)); picture = Path.GetFileName(filename); } else { var filename = Path.Combine(he.WebRootPath + "/images", "student.png"); picture = Path.GetFileName(filename); } SQLController SQL = new SQLController(); int ID = int.Parse(SQL.AspUserId()) + 1; var user = new ApplicationUser { UserName = model.Email, Email = model.Email, Nombre = model.Nombre, Apellido = model.Apellido, Telefono = model.Telefono, Tipo_Usuario = model.Tipo_Usuario, Imagen = picture, ID_Usuario = ID }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { if (!await _roleManager.RoleExistsAsync(RolesUsers.usuarioestudiante)) { await _roleManager.CreateAsync(new IdentityRole(RolesUsers.usuarioestudiante)); } await _userManager.AddToRoleAsync(user, RolesUsers.usuarioestudiante); _logger.LogInformation("User created a new account with password."); //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); //var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme); //await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl); await _signInManager.SignInAsync(user, isPersistent : false); _logger.LogInformation("User created a new account with password."); return(RedirectToLocal(returnUrl)); } AddErrors(result); } else { return(View(model)); } // If we got this far, something failed, redisplay form return(View()); }