Esempio n. 1
0
        public async Task<ActionResult> Create(AdminUserCreateModel model)
        {
            var user = new User();

            if (!TryUpdateModel2(user, model))
            {
                return Template(model.CreateTemplate(ControllerContext));
            }

            var db = MaintDbContext;
            var loginName = model.LoginName.Trim();
            if (await db.Users.AnyAsync(x => x.LoginName == loginName))
            {
                var errorMessage = string.Format(MaintCultureTextResources.ValidationDumplicate,
                    MaintCultureTextResources.AdminUserLoginName, loginName);
                ModelState.AddModelError("LoginName", string.Format(errorMessage, loginName));
                return Template(model.CreateTemplate(ControllerContext));
            }
            db.Users.Add(user);
            await db.SaveChangesAsync();
            await SetFlashAsync(new FlashMessage
            {
                Text = MaintCultureTextResources.SuccessToSave,
                MessageType = FlashMessageType.Success,
            });
            return Create();
        }
Esempio n. 2
0
 private IEnumerable<string> GetPrivileges(User user)
 {
     if (user.IsSuper)
     {
         return _privilegeLoader.Load().Items.Select(x => x.Name);
     }
     return user.Roles.ToList().SelectMany(x => x.PrivilegeArray );
 }
 public void SetInnerObject(User user)
 {
 }
Esempio n. 4
0
 public void SetInnerObject(User user)
 {
     UserName = user.UserName;
     LoginName = user.LoginName;
     IsSuper = user.IsSuper;
     DateOfBirth = user.DateOfBirth;
     Gender = user.Gender;
     Culture = user.CultureId;
 }