Beispiel #1
0
        public static UserModel MapUserModel(Account account, bool deepLoad, bool loadUserInformation = false)
        {
            if (account != null)
            {
                UserModel userModel = new UserModel()
                {
                    Id        = account.ID,
                    FirstName = account.FirstName,
                    LastName  = account.LastName,
                    Username  = account.UserName,
                    Image     = account.Image,
                    ClubId    = account.ClubId,
                    Gender    = (Gender)account.Gender
                };

                userModel.Club = new ClubModel()
                {
                    Id        = account.ClubId,
                    Name      = account.Club.Name,
                    ShortName = account.Club.ShortName,
                    Image     = account.Club.Image
                };

                if (deepLoad)
                {
                    Parallel.Invoke(() =>
                    {
                        userModel.Token = AccountBLL.GetUserSession(account.ID);
                    }, () =>
                    {
                        foreach (var item in account.AccountAccess)
                        {
                            foreach (var right in item.Accessright.Accessright_Right)
                            {
                                userModel.AccessRightsRight.Add(new AccessrightRightModel()
                                {
                                    AccessType      = (AccessType)right.AccessType,
                                    AccessTypeRight = (AccessTypeRight)right.AccessTypeRight,
                                    Id = right.Id
                                });
                            }
                        }
                    }, () =>
                    {
                        foreach (var item in account.AccountAccess)
                        {
                            userModel.AccessRights.Add(new AccessrightModel()
                            {
                                Id          = item.Accessright.ID,
                                Name        = item.Accessright.Name,
                                Description = item.Accessright.Description
                            });
                        }
                    }, () =>
                    {
                        Account_Information information = AccountBLL.GetAccountSettings(userModel.Id);
                        if (information != null)
                        {
                            userModel.UserInformation = new UserInformationModel()
                            {
                                Email      = information.Email,
                                City       = information.City,
                                Occupation = information.Occupation,
                                Phone      = information.Phone,
                                Street     = information.Street,
                                Zip        = information.Zip,
                                Birthday   = information.Birthday,
                                Grade      = (SW.Core.Enums.Grade)information.Grade,
                                Weight     = information.Weight,
                                Theme      = information.Theme
                            };
                        }
                    }, () =>
                    {
                        userModel.AccountAccess = AccountAccessModel.MapAccountAccesses(AccountBLL.GetAccountAccesses(userModel.Id));
                    }, () =>
                    {
                        userModel.GenericValues = AccountInformationGeneric.MapValues(
                            AccountBLL.GetGenericValues(userModel.Id, userModel.ClubId));
                    });
                }
                else if (loadUserInformation)
                {
                    Account_Information information = AccountBLL.GetAccountSettings(userModel.Id);
                    if (information != null)
                    {
                        userModel.UserInformation = new UserInformationModel()
                        {
                            Email      = information.Email,
                            City       = information.City,
                            Occupation = information.Occupation,
                            Phone      = information.Phone,
                            Street     = information.Street,
                            Zip        = information.Zip,
                            Birthday   = information.Birthday,
                            Grade      = (SW.Core.Enums.Grade)information.Grade,
                            Weight     = information.Weight,
                            Theme      = information.Theme
                        };
                    }
                }

                return(userModel);
            }

            return(new UserModel()
            {
                GenericValues = AccountInformationGeneric.MapValues(
                    AccountBLL.GetGenericValues(0, 0))
            });
        }