Ejemplo n.º 1
0
        public IHttpActionResult Edit(AccountEditViewModelItem request)
        {
            AccountEditViewModel viewmodel = new AccountEditViewModel();
            UserDataController   dataCtrl  = new UserDataController();

            try
            {
                User updateModel = dataCtrl.GetItem(request.ID);
                updateModel.ToModel(request);

                if (request.OldPassword != null && request.NewPassword1 != null && request.NewPassword2 != null)
                {
                    var newPassword = PasswordHelper.ChangePassword(dataCtrl.GetItem(UserHelper.CurrentUserID), request.OldPassword, request.NewPassword1, request.NewPassword2);
                    dataCtrl.ChangePassword(UserHelper.CurrentUserID, newPassword);
                    viewmodel.AddSuccessMessage("Passwort wurde geändert.");
                }

                updateModel = dataCtrl.Update(updateModel);
                viewmodel.Data.FromModel(updateModel);
            }
            catch (WrongPasswordException)
            {
                return(Warning(viewmodel, "Das eingegebene Passwort stimmt nicht."));
            }
            catch (PasswordsNotEqualException)
            {
                return(Warning(viewmodel, "Die eingegebenen Passwörter stimmt nicht überein."));
            }
            catch (Exception ex)
            {
                return(Error(viewmodel, ex));
            }

            return(Ok(viewmodel, "Profil wurde aktualisiert."));
        }
Ejemplo n.º 2
0
        public static User ToModel(this User model, AccountEditViewModelItem viewmodel)
        {
            model.FirstName = viewmodel.FirstName;
            model.LastName  = viewmodel.LastName;
            model.Nickname  = viewmodel.Nickname;
            model.Email     = viewmodel.Email;
            model.SteamID   = viewmodel.SteamID;
            model.BattleTag = viewmodel.BattleTag;

            return(model);
        }
Ejemplo n.º 3
0
        public static AccountEditViewModelItem FromModel(this AccountEditViewModelItem viewmodel, User model)
        {
            viewmodel.ID           = model.ID;
            viewmodel.FirstName    = model.FirstName;
            viewmodel.LastName     = model.LastName;
            viewmodel.Nickname     = model.Nickname;
            viewmodel.Image        = Properties.Settings.Default.imageAbsolutePath + "team/no_image.png"; // TODO
            viewmodel.Email        = model.Email;
            viewmodel.SteamID      = model.SteamID;
            viewmodel.BattleTag    = model.BattleTag;
            viewmodel.Newsletter   = model.Newsletter;
            viewmodel.OldPassword  = null;
            viewmodel.NewPassword1 = null;
            viewmodel.NewPassword2 = null;

            return(viewmodel);
        }