Ejemplo n.º 1
0
        public IHttpActionResult Update(UserModel model)
        {
            log.Debug("Call to ExternalAccountController.EditUser");

            if (model == null)
            {
                return(BadRequest("Parameters missing."));
            }

            var user = _sipAccountManager.GetByUserName(model.UserName);

            if (user == null)
            {
                return(NotFound());
            }

            // Set new values on "updatable" properties
            user.DisplayName = model.DisplayName;
            user.Comment     = model.Comment;

            try
            {
                _sipAccountManager.Update(user);
                return(Ok("User updated"));
            }
            catch (Exception ex)
            {
                log.Error(ex, "Could not update user");
                return(InternalServerError(new ApplicationException("User could not be updated.")));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Edit(SipAccountEditFormViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new SipAccount
                {
                    Id              = model.Id,
                    UserName        = model.UserName.Trim(),
                    DisplayName     = model.DisplayName,
                    Comment         = model.Comment,
                    ExtensionNumber = model.ExtensionNumber,
                    AccountType     = model.AccountType,
                    AccountLocked   = model.AccountLocked,
                    Password        = model.Password,
                    Owner           = _ownersRepository.GetById(model.OwnerId),
                    CodecType       = _codecTypeRepository.GetById(model.CodecTypeId),
                };

                try
                {
                    if (model.ChangePassword)
                    {
                        _sipAccountManager.UpdatePassword(user.Id, model.Password);
                    }

                    _sipAccountManager.Update(user);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    log.Error(ex, "Could not edit SIP account");
                    if (ex is ApplicationException)
                    {
                        ModelState.AddModelError("EditUser", ex.Message);
                    }
                    else
                    {
                        ModelState.AddModelError("EditUser", Resources.Sip_Account_Could_Not_Be_Saved);
                    }
                }
            }

            SetListData(model);
            return(View("Edit", model));
        }