Esempio n. 1
0
        public async Task CreateFolderAsync(FolderBO folder)
        {
            Validation.Validate.NotNull(folder);

            var entity = new Entities.Folder
            {
                Name           = folder.Name,
                ParentFolderId = folder.ParentFolderId
            };

            await uow.FolderRepository.CreateAsync(entity);
        }
Esempio n. 2
0
        public void UpdateFolder(FolderBO folder)
        {
            Validation.Validate.NotNull(folder);

            var entity = new Entities.Folder
            {
                Id             = folder.Id,
                Name           = folder.Name,
                ParentFolderId = folder.ParentFolderId
            };

            uow.FolderRepository.Update(entity);
        }
Esempio n. 3
0
        public async Task <AuthTokens> RegisterAsync(RegistrationData data)
        {
            Validate.NotNull(data, "Registration data");
            Validate.NotNull(data.FirstName, "First name");
            Validate.NotNull(data.LastName, "Last name");
            Validate.NotNull(data.Email, "Email");
            Validate.NotNull(data.LanguageCode, "Language code");

            {
                var temp = (await uow.UserProfileRepository.GetByConditionAsync(x => x.Email == data.Email)).FirstOrDefault();
                if (temp != null)
                {
                    throw new Exception("Email already in use");
                }
            }

            var language = await FindEntityAsync(uow.LanguageRepository, x => x.ShortCode == data.LanguageCode);

            var enc = cs.EncryptPassword(data.Password);

            var rootFolder = new Entities.Folder
            {
                Name           = "Root",
                ParentFolderId = null
            };

            var settings = new Entities.UserSettings
            {
                LanguageId = language.Id,
                Folder     = rootFolder
            };

            var profile = new Entities.UserProfile
            {
                FirstName    = data.FirstName,
                LastName     = data.LastName,
                Email        = data.Email,
                UserSettings = new System.Collections.Generic.List <Entities.UserSettings> {
                    settings
                }
            };

            var user = new Entities.AppUser
            {
                Username     = "******",
                PasswordHash = enc,
                UserProfile  = profile
            };

            await uow.AppUserRepository.CreateAsync(user);

            user.Username = cs.GenerateUsername();
            uow.AppUserRepository.Update(user);

            var tokens = GenerateTokens(user);

            var session = new Entities.Session
            {
                AppUserId = user.Id,
                Token     = tokens.RefreshToken,
                CreatedAt = DateTime.UtcNow.ToLongTimeString()
            };

            await uow.SessionRepository.CreateAsync(session);

            return(tokens);
        }