public Common.DTO.AccountDto CreateAccount(Common.DTO.AccountDto account, Common.DTO.UserDto user)
        {
            SecurityUserTDataAccess userDa = new SecurityUserTDataAccess();
            var dbUser = userDa.GetSingle(it => it.UserId == user.UserId);

            if (dbUser != null)
            {
                account.UserId = user.UserId;
                this.Insert(account);
                if (account.ApplicationDomainDtoList != null && account.ApplicationDomainDtoList.Count > 0)
                {
                    List <AccountToAppDomainDto>  accToAppList = new List <AccountToAppDomainDto>();
                    AccountToAppDomainTDataAccess accToAppDa   = new AccountToAppDomainTDataAccess();
                    foreach (var item in account.ApplicationDomainDtoList)
                    {
                        AccountToAppDomainDto accToApp = new AccountToAppDomainDto()
                        {
                            AccountId   = account.AccountId,
                            AppDomainId = item.ApplicationDomainId
                        };
                        accToAppList.Add(accToApp);
                    }
                    if (accToAppList.Count > 0)
                    {
                        accToAppDa.Insert(accToAppList);
                    }
                }
            }
            else
            {
                account.Response.AddBusinessException("کاربر موجود نیست!", BusinessExceptionEnum.Validation);
            }

            return(account);
        }
        public Framework.Common.Service.Message.ResponseDto UpdateAccount(Common.DTO.AccountDto account)
        {
            ResponseDto response = new ResponseDto();
            AccountToAppDomainTDataAccess accAppDa = new AccountToAppDomainTDataAccess();
            var dbAccount = this.GetSingle(it => it.AccountId == account.AccountId);

            if (dbAccount != null)
            {
                List <AccountToAppDomainDto> deletedAppDomain  = new List <AccountToAppDomainDto>();
                List <AccountToAppDomainDto> insertedAppDomain = new List <AccountToAppDomainDto>();
                foreach (var item in account.ApplicationDomainDtoList)
                {
                    if (item.State == Framework.Common.CommonBase.DtoObjectState.Deleted)
                    {
                        var accApp = accAppDa.GetSingle(it => it.AppDomainId == item.ApplicationDomainId && it.AccountId == account.AccountId);
                        if (accApp != null)
                        {
                            deletedAppDomain.Add(accApp);
                        }
                    }
                    if (item.State == Framework.Common.CommonBase.DtoObjectState.Inserted)
                    {
                        AccountToAppDomainDto newDto = new AccountToAppDomainDto()
                        {
                            AccountId   = account.AccountId,
                            AppDomainId = item.ApplicationDomainId
                        };
                        insertedAppDomain.Add(newDto);
                    }
                }
                if (deletedAppDomain.Count > 0)
                {
                    accAppDa.Delete(deletedAppDomain);
                }
                if (insertedAppDomain.Count > 0)
                {
                    accAppDa.Insert(insertedAppDomain);
                }
                dbAccount.Enabled = account.Enabled;

                dbAccount.Username = account.Username;
                this.Update(dbAccount);
            }
            else
            {
                response.Response.AddBusinessException("حساب کاربری موجود نیست!", BusinessExceptionEnum.Validation);
            }
            return(response);
        }
Exemple #3
0
        public Framework.Common.Service.Message.ResponseDto DeAssignAccountAppDomain(Common.DTO.AccountDto account, int appDomain)
        {
            AccountTDataAccess accountDa = new AccountTDataAccess();
            ResponseDto        response  = new ResponseDto();
            var dbAccount = accountDa.GetSingle(it => it.AccountId == account.AccountId);

            if (dbAccount != null)
            {
                AccountToAppDomainTDataAccess accToDomainDa = new AccountToAppDomainTDataAccess();
                var dbAccToDomain = accToDomainDa.GetSingle(it => it.AccountId == account.AccountId && it.AppDomainId == appDomain && it.ExpireDate == null);
                dbAccToDomain.ExpireDate = null;
                accToDomainDa.Update(dbAccToDomain);
            }
            else
            {
                response.Response.AddBusinessException("حساب کاربری وجود ندارد!", BusinessExceptionEnum.Operational);
            }
            return(response);
        }