/// <summary> /// /// </summary> /// <param name="userId">user id</param> /// <returns>user profile model</returns> public ProfileModel GetUserProfileModel(int userId) { ProfileModel model = UserModel.DbEntityToProfilModel(UserOp.GetUser(userId)); model.AllProperties = PropertyModel.ToModelList(PropertyOp.Properties); model.Properties = PropertyModel.ToModelList(PropertyOp.GetUserProperties(userId)); return(model); }
/// <summary> /// updates user profile /// </summary> /// <param name="profileModel">updated user prifile</param> /// <returns>updated profile model</returns> public ProfileModel UpdateProfile(ProfileModel profileModel) { UserOp.UpdateUser(profileModel.GetUserEntity()); List <Property> pm = PropertyModel.ToEntityList(profileModel.Properties); pm = pm.GroupBy(test => test.Name) .Select(grp => grp.First()) .ToList(); profileModel.Properties = PropertyModel.ToModelList(PropertyOp.AddUserProperties(profileModel.Id, pm)); return(profileModel); }
/// <summary> /// returns all Users /// </summary> /// <returns></returns> public List <UserShortModel> GetAllUsers() { List <UserShortModel> list = new List <UserShortModel>(); foreach (User u in UserOp.GetAllUsers()) { list.Add(new UserShortModel(u.Id, u.FirstName, u.LastName)); } userList = list; return(userList); }
public ActionResult Registration(UserModel model) { if (ModelState.IsValid) { if (UserOp.Register(model.Email, model.FirstName, model.LastName, model.Password, model.SecretQuestion, model.Answer, model.StakeholderDescription)) { LoginModel lm = new LoginModel(); lm.Email = model.Email; lm.Password = model.Password; return(Login(lm)); } } ModelState.AddModelError("", "Email already exists"); return(View(model)); }
/// <summary> /// performs login /// </summary> /// <param name="email">user e-mail adress</param> /// <param name="password">user password</param> /// <returns>is login is successful then usermodel is returned else null</returns> public UserModel Login(string email, string password) { User user = UserOp.Login(email, password); if (user != null) { UserModel model = new UserModel(); model.Id = user.Id; model.FirstName = user.FirstName; model.LastName = user.LastName; model.Password = user.PasswordHash; model.SecretQuestion = user.SecretQuestion; model.StakeholderDescription = user.StakeholderDescription; model.Email = user.Email; return(model); } return(null); }
/// <summary> /// returns List of comments for issue alternatives /// </summary> /// <param name="issueId"></param> /// <param name="userId"></param> /// <returns></returns> private List <CommentModel> GetComments(int issueId, int userId) { CommentModel cm = new CommentModel(); List <CommentModel> list = cm.ToModelList(CommentOp.GetAlternativeComments(issueId, userId), cm); List <KeyValuePair <int, string> > userList = UserOp.GetUserNames(list.Select(x => x.UserId).Distinct().ToList()); List <KeyValuePair <int, string> > anonymousUsers = new List <KeyValuePair <int, string> >(); List <KeyValuePair <int, string> > anonNames = new List <KeyValuePair <int, string> >(); int i = 1; Random rnd = new Random(); KeyValuePair <int, string> randName; List <int> usedRands = new List <int>(); bool added; int rNumber = 0; foreach (KeyValuePair <int, string> userkvp in userList) { added = false; while (added == false) { rNumber = rnd.Next(1, 999999); if (!usedRands.Contains(rNumber)) { usedRands.Add(rNumber); added = true; } } anonNames.Add(new KeyValuePair <int, string>(userkvp.Key, "Anonymous " + rNumber)); i++; } foreach (CommentModel model in list) { if (model.Anonymous) { model.Name = anonNames.Where(x => x.Key == model.UserId).FirstOrDefault().Value; } else { model.Name = userList.Where(x => x.Key == model.UserId).FirstOrDefault().Value; } } return(list); }