Example #1
0
 public data.User UpdateUser(User user)
 {
     var query = Query.EQ("_id", user._id);
     _Users.Collection.Update(query, Update.Replace<User>(user));
     return user;
 }
        public ActionResult Update(User updatedUser, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                var user = UserContext.Current.CurrentUser;
                var currentuser = UserSvc.GetUserById(user.id);

                currentuser.Firstname = updatedUser.Firstname;
                currentuser.Lastname = updatedUser.Lastname;
                currentuser.AboutYou = updatedUser.AboutYou;

                Address result = null;

                if (!string.IsNullOrEmpty(updatedUser.Location.Address))
                {
                    result = GeocodeSvc.GeoCode(updatedUser.Location.Address).FirstOrDefault();
                }

                if (result != null)
                {
                    if (currentuser.Location == null)
                        currentuser.Location = new NestedLocation();

                    currentuser.Location.Address = updatedUser.Location.Address;
                    currentuser.Location.Address = result.FormattedAddress;
                    currentuser.Location.Coordinates = new double[2
                        ];

                    currentuser.Location.Coordinates[0] = result.Coordinates.Longitude;
                    currentuser.Location.Coordinates[1] = result.Coordinates.Latitude;

                    UserContext.Current.Notify = "Profile updated !";
                }
                else
                {
                    UserContext.Current.Notify = "Profile updated with warning: Address not retreived.";
                }

                var upload = ImageSvc.UpdateImage(file, currentuser._id.ToString(), Server.MapPath(ConfigurationManager.AppSettings["userdirpicture"]), currentuser.Picture);

                if (!string.IsNullOrEmpty(upload))
                    currentuser.Picture = upload;

                UserSvc.UpdateUser(currentuser);

                UserContext.Current.NotifyType = notificationType.success.Value();
            }

            return RedirectToAction("Index");
        }
Example #3
0
 //Check if a password matches it salt.
 private bool VerifyPassword(User user, string password)
 {
     return user.Password_Hash == EncodePassword(password, user.Password_Salt);
 }