Exemplo n.º 1
0
        public Task CreateAsync(CcmUser user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            userManager.Create(user);
            return(null);
        }
Exemplo n.º 2
0
        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));
        }
Exemplo n.º 3
0
        public IHttpActionResult Add(AddUserModel model)
        {
            log.Debug("Call to ExternalAccountController.AddUser");

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

            var user = new CcmUser
            {
                Id          = Guid.NewGuid().ToString(),
                UserName    = model.UserName.Trim(),
                DisplayName = model.DisplayName,
                Comment     = model.Comment,
                UserType    = UserType.SIP,
                Owner       = _ownersRepository.GetByName(ApplicationConstants.SrOwnerName),
                CodecType   = _codecTypeRepository.Find(ApplicationConstants.PersonligaCodecTypeName).FirstOrDefault(),
                CreatedBy   = User.Identity.Name,
                UpdatedBy   = User.Identity.Name
            };

            try
            {
                var existingUser = _userManager.FindByUserName(user.UserName);
                if (existingUser != null)
                {
                    return(Conflict());
                }

                _userManager.Create(user, model.Password);
                return(Created(Url.Content("get?username="******"User created"));
            }
            catch (Exception ex)
            {
                log.Error("Could not create user", ex);
                return(InternalServerError());
            }
        }