Exemplo n.º 1
0
        /// <summary>
        /// Save or update the list of records
        /// </summary>
        /// <param name="request">the request containing the entities</param>
        /// <returns></returns>
        public JarsUserResponse Any(StoreJarsUser request)
        {
            return(ExecuteFaultHandledMethod(() =>
            {
                IAuthRepository ssAuthRepo = ServiceStackHost.Instance.GetAuthRepository();
                IUserAuth ssUser = ssAuthRepo.GetUserAuthByUserName(request.UserAccount.UserName);

                if (ssUser == null && request.UserAccount.Id != 0)
                {
                    throw HttpError.NotFound(request.UserAccount.UserName);
                }

                UserAuth newUserA = new UserAuth();
                if (request.UserAccount.Id == 0)
                {
                    newUserA.PopulateWith(request.UserAccount);
                    newUserA.LockedDate = DateTime.UtcNow;
                    newUserA.RecoveryToken = Guid.NewGuid().ToString("N");
                    ssUser = ssAuthRepo.CreateUserAuth(newUserA, "Password123");
                    //sendemailtouser
                }
                else
                {
                    newUserA.PopulateWith(ssUser);
                    newUserA.PopulateWith(request.UserAccount);
                    ssAuthRepo.UpdateUserAuth(ssUser, newUserA);
                }


                //so the user should be updated here..

                IJarsUserRepository repository = _DataRepositoryFactory.GetDataRepository <IJarsUserRepository>();
                JarsUserResponse response = new JarsUserResponse();
                if (request.UserAccount != null)
                {
                    JarsUser dbUser = new JarsUser();
                    if (request.UserAccount.Id != 0)
                    {
                        dbUser = repository.GetById(request.UserAccount.Id, true);
                    }
                    else
                    {
                        dbUser.IsActive = false;
                    }

                    dbUser.PopulateWith(ssUser);
                    dbUser.Id = request.UserAccount.Id;
                    dbUser.Settings = request.UserAccount.Settings.ConvertAllTo <JarsSetting>().ToList();

                    dbUser = repository.CreateUpdate(dbUser, CurrentSessionUsername);
                    response.UserAccount = dbUser.ConvertTo <JarsUserDto>();
                }
                //else
                //    response.UserAccounts = repository.CreateUpdateList(request.UserAccounts).ToList();
                return response;
            }));
        }
Exemplo n.º 2
0
        public override void OnSaveData()
        {
            if (dxValidator.Validate())
            {
                JarsUser saveObject = defaultBindingSource.Current as JarsUser;
                ApplyPermissionsToUser(saveObject);
                StoreJarsUser store = new StoreJarsUser()
                {
                    IsAppointment = false,
                    UserAccount   = saveObject.ConvertTo <JarsUserDto>()
                };

                JarsUserResponse resp = ServiceClient.Post(store);
                saveObject = resp.UserAccount.ConvertTo <JarsUser>();
                base.OnSaveData();
                ctr_txtUserName.Enabled = false;
            }
        }