public override Task OnDisconnected(bool stopCalled) { if (Context.User.Identity.IsAuthenticated) { IUserDAL us = new UserDALImp(); User user = us.Get_User(Convert.ToInt32(Context.Request.User.Identity.Name)); if (UserConnections.TryGetValue(user.idUser, out WsUserModel usu)) { usu.connectionsId = usu.connectionsId.FindAll(o => !o.Equals(Context.ConnectionId)); if (usu.connectionsId.Count == 0) { UserConnections.Remove(usu.user.idUser); } } } return(base.OnDisconnected(stopCalled)); }
public ActionResult Edit(int id) { if (TempData["msg"] != null) { ViewBag.msg = TempData["msg"].ToString(); TempData.Remove("msg"); } User us; UserDALImp imp = new UserDALImp(); us = imp.Get_User(id); us.password = "******"; if (!us.rol.Equals("C")) { us.height = 10; us.weight = 10; } return(View(UserViewModel.Converter(us))); }
private WsUserModel GetCurUser() { IUserDAL us = new UserDALImp(); User user = us.Get_User(Convert.ToInt32(Context.Request.User.Identity.Name)); if (UserConnections.TryGetValue(user.idUser, out WsUserModel usu)) { return(usu); } else if (user != null) { usu = new WsUserModel { user = user, connectionsId = new List <string>(), idActivityAssistance = -5 }; usu.connectionsId.Add(Context.ConnectionId); UserConnections.Add(usu.user.idUser, usu); return(usu); } return(null); }
public override Task OnConnected() { if (Context.User.Identity.IsAuthenticated) { IUserDAL us = new UserDALImp(); User user = us.Get_User(Convert.ToInt32(Context.Request.User.Identity.Name)); if (UserConnections.TryGetValue(user.idUser, out WsUserModel usu)) { usu.connectionsId.Add(Context.ConnectionId); } else { usu = new WsUserModel { user = user, connectionsId = new List <string>(), idActivityAssistance = -5 }; usu.connectionsId.Add(Context.ConnectionId); UserConnections.Add(usu.user.idUser, usu); } } return(base.OnConnected()); }
public ActionResult EditProfile(UserViewModel userVM) { string key = ConfigurationManager.AppSettings["SecretKey"]; bool result = false; User aux; using (var unit = new UnitWork <User>()) { aux = unit.genericDAL.Get(userVM.idUser); } if (aux != null) { userVM.password = aux.password; if (!userVM.rol.Equals("C")) { userVM.height = 10; userVM.weight = 10; } } if (ModelState.IsValid) { UserDALImp imp = new UserDALImp(); string msg = imp.ValidationUserCreation(UserViewModel.Converter(userVM)); if (msg.Equals("")) { userVM.email = Security.Security.EncryptString(key, userVM.email); User user = UserViewModel.Converter(userVM); try { using (var unit = new UnitWork <User>()) { unit.genericDAL.Update(user); result = unit.Complete(); } if (result && userVM.rol.Equals("C") && (aux.height != userVM.height || aux.weight != userVM.weight)) { UserDataHistory udh = new UserDataHistory() { date = DateTime.Now, heigth = user.height, weight = user.weight, idUser = user.idUser }; using (var u = new UnitWork <UserDataHistory>()) { u.genericDAL.Add(udh); u.Complete(); } } ViewBag.msg = (!result) ? "No se pudo actualizar el perfil" : "El perfil se ha modificado"; } catch (Exception e) { result = false; } } else { ViewBag.msg = msg; ViewBag.status = false; } } else { result = false; } ViewBag.status = result; if (result) { userVM.password = null; userVM.email = Security.Security.DecryptString(key, userVM.email); Session["User"] = userVM; } return(EditProfile()); }