public ActionResult Edit(Guid id) { if (id == Guid.Empty) { return(RedirectToAction("Index")); } var codecType = _codecTypeRepository.GetById(id); if (codecType == null) { return(RedirectToAction("Index")); } return(View(codecType)); }
public ActionResult Create(UserFormViewModel model) { if (ModelState.IsValid) { var user = new CcmUser { Comment = model.Comment, DisplayName = model.DisplayName, FirstName = model.UserType != UserType.SIP ? model.FirstName : string.Empty, Id = Guid.NewGuid().ToString(), LastName = model.UserType != UserType.SIP ? model.LastName : string.Empty, UserName = model.UserName.Trim(), UserType = model.UserType, Owner = model.UserType == UserType.SIP ? _ownersRepository.GetById(model.OwnerId) : null, CodecType = model.UserType == UserType.SIP ? _codecTypeRepository.GetById(model.CodecTypeId) : null, CreatedBy = User.Identity.Name, UpdatedBy = User.Identity.Name, RoleId = model.RoleId }; try { var userIsLocalAdmin = _userManager.UserIsLocalAdmin(User.Identity.Name); _userManager.Create(user, model.Password, userIsLocalAdmin); return(RedirectToAction("Index")); } catch (Exception ex) { log.Error("Could not create user", ex); if (ex is ApplicationException) { ModelState.AddModelError("CreateUser", ex.Message); } else { ModelState.AddModelError("CreateUser", "Användaren kunde inte skapas"); } } } SetListData(model); return(View(model)); }
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)); }