Exemplo n.º 1
0
        public async Task <Guid> ExecuteAsync(CreateAchievementCommandRequestModel commandRequest)
        {
            var userRecord = await this.usersRepository.GetAsync(commandRequest.UserId);

            if (userRecord is null)
            {
                throw new HttpException(HttpStatusCode.NotFound, $"User (ID: {commandRequest.UserId}) cannot be found.");
            }

            var maturityLevelRecord = await this.maturityLevelsRepository.GetAsync(commandRequest.MaturityLevelId);

            if (maturityLevelRecord is null)
            {
                throw new HttpException(HttpStatusCode.NotFound, $"MaturityLevel (ID: {commandRequest.MaturityLevelId}) cannot be found.");
            }

            var user          = User.FromTableRecord(userRecord);
            var maturityLevel = MaturityLevel.FromTableRecord(maturityLevelRecord);
            var achievement   = new Achievement
            {
                Id              = Guid.NewGuid(),
                UserId          = commandRequest.UserId,
                MaturityLevelId = commandRequest.MaturityLevelId,
                AchievementDate = commandRequest.AchievementDate,
                Comment         = commandRequest.Comment
            };

            user.TotalMaturityPoints += (int)maturityLevel.BeltLevel;

            await this.achievementsRepository.CreateAsync(achievement.ToTableRecord());

            var numberOfUniqueAchievements = await this.achievementsRepository.GetUniqueAchievementsCountByUserId(user.Id);

            var numberOfGreenBeltAchievements = await this.achievementsRepository.GetGreenBeltAchievementCountByUserId(user.Id);

            var numberOfBlackBeltAchievements = await this.achievementsRepository.GetBlackBeltAchievementCountByUserId(user.Id);

            if (numberOfUniqueAchievements >= 9 && numberOfBlackBeltAchievements >= 3)
            {
                user.Belt = BeltType.Black;
            }
            else if (numberOfUniqueAchievements >= 3 && numberOfBlackBeltAchievements >= 1 && numberOfGreenBeltAchievements >= 2)
            {
                user.Belt = BeltType.Green;
            }
            else if (numberOfUniqueAchievements >= 5)
            {
                user.Belt = BeltType.White;
            }
            else
            {
                user.Belt = BeltType.None;
            }

            await this.usersRepository.UpdateAsync(user.ToTableRecord());

            return(achievement.Id);
        }
Exemplo n.º 2
0
        public async Task <MaturityLevel> ExecuteAsync(GetMaturityLevelQueryRequestModel queryRequest)
        {
            var maturityLevel = await this.maturityLevelsRepository.GetAsync(queryRequest.Id);

            if (maturityLevel == null)
            {
                throw new HttpException(HttpStatusCode.NotFound, $"MaturityLevel (ID: {queryRequest.Id}) cannot be found.");
            }

            return(MaturityLevel.FromTableRecord(maturityLevel));
        }
 public static GetMaturityLevelResponseModel FromBusinessModel(MaturityLevel maturityLevel)
 {
     return(new GetMaturityLevelResponseModel
     {
         Id = maturityLevel.Id,
         MaturityCategoryId = maturityLevel.MaturityCategoryId,
         BeltLevel = maturityLevel.BeltLevel,
         Description = maturityLevel.Description,
         CreatedAt = maturityLevel.CreatedAt,
         UpdatedAt = maturityLevel.UpdatedAt
     });
 }
        public async Task <IEnumerable <MaturityLevel> > ExecuteAsync()
        {
            var maturityLevels = await this.maturityLevelsRepository.GetAllAsync();

            var maturityLevelList = new List <MaturityLevel>();

            foreach (var maturityLevel in maturityLevels)
            {
                maturityLevelList.Add(MaturityLevel.FromTableRecord(maturityLevel));
            }

            return(maturityLevelList);
        }
        public async Task <IEnumerable <MaturityLevel> > GetMaturityLevelsByCategoryId(Guid categoryId)
        {
            var records = await this.maturityLevelsRepository.GetByCategoryIdAsync(categoryId);

            var entities = new List <MaturityLevel>();

            foreach (var record in records)
            {
                entities.Add(MaturityLevel.FromTableRecord(record));
            }

            return(entities);
        }
        public async Task <IEnumerable <MaturityLevel> > ExecuteAsync(GetMaturityLevelsByCategoryIdQueryRequestModel queryRequest)
        {
            var maturityCategory = await this.maturityCategoriesRepository.GetAsync(queryRequest.CategoryId);

            if (maturityCategory is null)
            {
                throw new HttpException(HttpStatusCode.NotFound, $"MaturityCategory (ID: {queryRequest.CategoryId}) cannot be found.");
            }

            var maturityLevelRecords = await this.maturityLevelsRepository.GetByCategoryIdAsync(queryRequest.CategoryId);

            var maturityLevels = new List <MaturityLevel>();

            foreach (var maturityLevelRecord in maturityLevelRecords)
            {
                maturityLevels.Add(MaturityLevel.FromTableRecord(maturityLevelRecord));
            }

            return(maturityLevels);
        }
Exemplo n.º 7
0
        public async Task <Guid> ExecuteAsync(CreateMaturityLevelCommandRequestModel commandRequest)
        {
            var maturityCategory = await this.maturityCategoriesRepository.GetAsync(commandRequest.MaturityCategoryId);

            if (maturityCategory == null)
            {
                throw new HttpException(HttpStatusCode.NotFound, $"MaturityCategory (ID: {commandRequest.MaturityCategoryId}) cannot be found.");
            }

            var maturityLevel = new MaturityLevel
            {
                Id = Guid.NewGuid(),
                MaturityCategoryId = commandRequest.MaturityCategoryId,
                BeltLevel          = commandRequest.BeltLevel,
                Description        = commandRequest.Description
            };

            await this.maturityLevelsRepository.CreateAsync(maturityLevel.ToTableRecord());

            return(maturityLevel.Id);
        }