Beispiel #1
0
        private bool ModifiedUserModel(UserModel user, UserInterfaceModel model)
        {
            try
            {
                user.UserName = model.UserName;
                user.Name     = model.Name;

                if (model.NewExpiration.HasValue)
                {
                    user.Expiration = ((DateTime)model.NewExpiration).ToLocalTime();
                }

                user.PasswordSkipCnt = model.PasswordSkipCnt;

                user.Email          = model.Email;
                user.EmailConfirmed = model.EmailConfirmed;

                if (model.LockoutEndData.HasValue)
                {
                    user.LockoutEndData = (DateTime)model.LockoutEndData;
                }

                user.LockoutEnabled    = model.LockoutEnabled;
                user.AccessFailedCount = model.AccessFailedCount;

                user.Enabled = model.Enabled;
                user.Deleted = model.Deleted;
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Beispiel #2
0
        public async Task <IHttpActionResult> PutAsync(int id, [FromBody] UserInterfaceModel value)
        {
            try
            {
                if (id <= 0)
                {
                    return(BadRequest());
                }

                var result = await repository.ModifyUserAsync(id, value);

                if (result.Code != HttpStatusCode.OK)
                {
                    AddErrors(result.identityResult);
                    return(Content(result.Code, ModelState.GetErrorsDelprefix("value")));
                }
                var modifiedUser = await repository.GetUserByIdForInterfaceAsync(id);

                return(Ok(modifiedUser.resultData));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Beispiel #3
0
        public async Task <RepositoryResult <UserInterfaceModel> > CreateUserAsync(UserInterfaceModel createUser)
        {
            try
            {
                if (await AppUserManager.FindByIdAsync(createUser.Id) != null)
                {
                    return(new RepositoryResult <UserInterfaceModel>(HttpStatusCode.Conflict));
                }

                if (string.IsNullOrWhiteSpace(createUser.NewPassword))
                {
                    return(new RepositoryResult <UserInterfaceModel>(HttpStatusCode.BadRequest, "パスワードは必須項目です。"));
                }

                var user = new UserModel();
                user.UserName = createUser.UserName;
                user.Name     = createUser.Name;
                user.Email    = createUser.Email;
                user.Enabled  = createUser.Enabled;

                var result = new RepositoryResult <UserInterfaceModel>(HttpStatusCode.Created);
                result.identityResult = await AppUserManager.CreateAsync(user, createUser.NewPassword);

                if (!result.identityResult.Succeeded)
                {
                    result.Code = HttpStatusCode.BadRequest;
                }
                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public void Post([FromBody] UserInterfaceModel value)
 {
     _businessLogicService.Save(
         new BusinessLogicEntity {
         Property = value.Property
     }
         );
 }
Beispiel #5
0
        public ActionResult InterfaceSettings()
        {
            var model = new UserInterfaceModel();

            model.Token        = GetToken();
            model.CurrentTheme =
                RemontinkaServer.Instance.GetService <IWebSiteSettingsService>()
                .GetDevexpressTheme(model.Token.LoginName);
            return(View(model));
        }
Beispiel #6
0
 public ActionResult InterfaceSettings(UserInterfaceModel model)
 {
     model.Token = GetToken();
     if (ModelState.IsValid)
     {
         RemontinkaServer.Instance.GetService <IWebSiteSettingsService>()
         .SetDevexpressTheme(model.Token.LoginName, model.CurrentTheme);
         DevExpressHelper.Theme = model.CurrentTheme;
     }
     return(View(model));
 }
Beispiel #7
0
        public async Task <IHttpActionResult> PostAsync([FromBody] UserInterfaceModel value)
        {
            try
            {
                var result = await repository.CreateUserAsync(value);

                if (result.Code != HttpStatusCode.Created)
                {
                    // GetErrorResult(result);
                    AddErrors(result.identityResult);
                    return(Content(result.Code, ModelState.GetErrorsDelprefix("value")));
                }

                result = await repository.GetUserByNameForInterfaceAsync(value.UserName);

                var _UrlHelper = new UrlHelper(this.Request);
                var Url        = _UrlHelper.Link("GetUsersById", new { id = result.resultData.Id });
                return(Created(Url, result.resultData));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Beispiel #8
0
        public async Task <RepositoryResult <UserInterfaceModel> > ModifyUserAsync(int id, UserInterfaceModel modifiedUser)
        {
            try
            {
                if (id <= 0)
                {
                    return(new RepositoryResult <UserInterfaceModel>(HttpStatusCode.BadRequest));
                }

                using (DataContext dbContext = DataContext.Create())
                    using (DbContextTransaction tx = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
                    {
                        modifiedUser.Id = id;
                        UserModel user = await AppUserManager.FindByIdAsync(modifiedUser.Id);

                        if (user == null)
                        {
                            tx.Rollback();
                            return(new RepositoryResult <UserInterfaceModel>(HttpStatusCode.NotFound));
                        }

                        IdentityResult result;
                        if (!string.IsNullOrEmpty(modifiedUser.NewPassword))
                        {
                            string code = await AppUserManager.GeneratePasswordResetTokenAsync(user.Id);

                            result = await AppUserManager.ResetPasswordAsync(user.Id, code, modifiedUser.NewPassword);

                            if (!result.Succeeded)
                            {
                                tx.Rollback();
                                return(new RepositoryResult <UserInterfaceModel>(HttpStatusCode.BadRequest)
                                {
                                    identityResult = result
                                });
                            }
                        }

                        ModifiedUserModel(user, modifiedUser);
                        result = await AppUserManager.UpdateAsync(user);

                        if (!result.Succeeded)
                        {
                            tx.Rollback();
                            return(new RepositoryResult <UserInterfaceModel>(HttpStatusCode.BadRequest)
                            {
                                identityResult = result
                            });
                        }

                        tx.Commit();
                        return(new RepositoryResult <UserInterfaceModel>(HttpStatusCode.OK)
                        {
                            identityResult = result
                        });
                    }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }