public ActionResult Create(SipAccountCreateFormViewModel model) { if (ModelState.IsValid) { var user = new SipAccount { Id = Guid.NewGuid(), 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 { _sipAccountManager.Create(user); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error(ex, "Could not create SIP account"); if (ex is ApplicationException) { ModelState.AddModelError("CreateUser", ex.Message); } else { ModelState.AddModelError("CreateUser", Resources.Sip_Account_Could_Not_Be_Saved); } } } SetListData(model); return(View("Create", model)); }
public IHttpActionResult Add(AddUserModel model) { log.Debug("Call to ExternalAccountController.AddUser"); if (model == null) { return(BadRequest("Parameters missing.")); } var user = new SipAccount { Id = Guid.NewGuid(), UserName = model.UserName.Trim(), DisplayName = model.DisplayName, Comment = model.Comment, Owner = _ownersRepository.GetByName(Owners.SrOwnerName), CodecType = _codecTypeRepository.Find(CodecTypes.Personliga).FirstOrDefault(), Password = model.Password }; try { var existingUser = _sipAccountManager.GetByUserName(user.UserName); if (existingUser != null) { return(Conflict()); } _sipAccountManager.Create(user); return(Created(Url.Content("get?username="******"User created")); } catch (Exception ex) { log.Error(ex, "Could not create user"); return(InternalServerError()); } }