Ejemplo n.º 1
0
        private AchievementDto AggregateAchievements(IGrouping <string, DynamicTableEntity> achievements)
        {
            var names = achievements.Select(e => e.Properties["achievement"].StringValue).ToList();

            var result = new AchievementDto
            {
                Team         = achievements.Key,
                Achievements = new List <string>()
            };

            // Ok, so the following is way to hard coded, but the meetup starts in 5 min and
            // I don't have time left to do this properly :-)

            if (names.Contains("Mission1.1") &&
                names.Contains("Mission1.2") &&
                names.Contains("Mission1.3"))
            {
                result.Achievements.Add("Mission 1");
            }

            if (names.Contains("Mission2.1"))
            {
                result.Achievements.Add("Mission 2");
            }

            if (names.Contains("Mission3.1") &&
                names.Contains("Mission3.2") &&
                names.Contains("Mission3.3"))
            {
                result.Achievements.Add("Mission 3");
            }

            return(result);
        }
Ejemplo n.º 2
0
        public bool AddAchievement(AchievementDto dto)
        {
            SQLExecuteParam param = new SQLExecuteParam();

            param.obj = dto;
            param.sql = @"
                        INSERT INTO tb_achievement (
	                        title,
	                        content,
	                        `status`,
	                        is_deleted,
	                        creator,
	                        create_time
                        )
                        VALUES
	                        (
		                        @title,
		                        @content,
		                        1,
		                        0,
		                        @creator,
		                        now()
	                        )
                ";

            if (DBAgent.SQLExecuteReturnRows(param) == 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private async Task <HttpStatusCode> UpdateLessonCountAchievement(AchievementDto achievementDto, int userId, List <UserAchievementDto> userAchievementDtos)
        {
            UserAchievementDto lessonCountUserAchievementDto = userAchievementDtos
                                                               .Where(uad => uad.AchievementId == achievementDto.Id)
                                                               .FirstOrDefault();

            if (lessonCountUserAchievementDto == null)
            {
                PostUserAchievementDto postUserAchievementDto = new PostUserAchievementDto
                {
                    AchievementId = achievementDto.Id,
                    Completed     = achievementDto.RequiredCount == 1,
                    Progress      = 1,
                    UserId        = userId
                };

                return(await _userAchievementsService.PostUserAchievement(postUserAchievementDto));
            }
            else
            {
                await _userAchievementsService.ProgressUserAchievement(achievementDto, userId);

                return(HttpStatusCode.OK);
            }
        }
Ejemplo n.º 4
0
 public void LocalUnlock(AchievementDto achievement)
 {
     LogUtil.Log("Local unlock: " + achievement.id);
     achievement.completed        = true;
     achievement.percentCompleted = 100;
     UserManagement.Instance.Save();
 }
        private async Task <List <AchievementDto> > GetAllAchievements()
        {
            var achievements = await _mimoDbContext.Achievements
                               .Include(a => a.AchievementTypeFk)
                               .Select(a => new
            {
                a.Id,
                a.AchievementTypeFk.AchievementTypeName,
                a.RequiredCount
            })
                               .ToListAsync();

            List <AchievementDto> achievementDtos = new List <AchievementDto>();

            foreach (var achievement in achievements)
            {
                AchievementDto achievementDto = new AchievementDto
                {
                    Id = achievement.Id,
                    AchievementTypeName = achievement.AchievementTypeName,
                    RequiredCount       = achievement.RequiredCount
                };

                achievementDtos.Add(achievementDto);
            }

            return(achievementDtos);
        }
Ejemplo n.º 6
0
        public IActionResult Update(int id, [FromBody] AchievementDto achievementDto)
        {
            var model  = Mapper.Map <Achievement>(achievementDto);
            var result = _achievementService.Update(model);

            return(Ok());
        }
Ejemplo n.º 7
0

        
Ejemplo n.º 8
0
 public Achievement UpdateFromDto(AchievementDto achievementDto)
 {
     Id   = achievementDto.Id;
     Name = achievementDto.Name;
     //TODO: when categories will be noraml try catch can be removed
     //Category = Category != null ? achievementDto.Category.Name : "NULL";
     Category = achievementDto.Category;
     ImageUri = achievementDto.Src;
     return(this);
 }
Ejemplo n.º 9
0
        public IResult DeleteAchievement(AchievementDto achievementDto)
        {
            using WordBookContext db = new();
            Achievement deletedAchievement = db.Achievements.Where(a => a.AchievementId == achievementDto.AchievementId).SingleOrDefault();

            if (deletedAchievement == null)
            {
                return(new ErrorResult(Messages.AchievementNotFound));
            }
            db.Achievements.Remove(deletedAchievement);
            db.SaveChanges();
            return(new SuccessResult(Messages.AchievementDeleted));
        }
Ejemplo n.º 10
0
        public IResult UpdateAchievement(AchievementDto achievementDto)
        {
            using WordBookContext db = new();
            Achievement updatedAchievement = db.Achievements.Where(a => a.AchievementId == achievementDto.AchievementId).SingleOrDefault();

            if (updatedAchievement == null)
            {
                return(new ErrorResult(Messages.AchievementNotFound));
            }
            updatedAchievement.AchievementTypeId = achievementDto.AchievementTypeId;
            updatedAchievement.Score             = achievementDto.Score;
            updatedAchievement.UpdatedAt         = System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();
            db.SaveChanges();
            return(new SuccessResult(Messages.AchievementUpdated));
        }
Ejemplo n.º 11
0
        public void Achievement()
        {
            var player = "nick";
            var time   = TimeSpan.FromSeconds(213);
            var date   = DateTimeOffset.Now;

            var achievement = new AchievementDto()
            {
                Player = player, Time = time, Date = date
            };

            Assert.IsTrue(achievement.Player == player);
            Assert.IsTrue(achievement.Time == time);
            Assert.IsTrue(achievement.Date == date);
        }
Ejemplo n.º 12
0
        public async Task <List <AchievementDto> > GetMyAchievementsAsync(string userId)
        {
            var dtos         = new List <AchievementDto>();
            var achievements = await UnitOfWork.Achievements.GetUserAchievementsAsync(userId);

            achievements.ForEach(a =>
            {
                var achDto = new AchievementDto
                {
                    Name    = a.Name,
                    Price   = a.Price,
                    Reached = a.Reached
                };
                dtos.Add(achDto);
            });
            return(dtos);
        }
        public async Task <HttpStatusCode> ProgressUserAchievement(AchievementDto achievementDto, int userId)
        {
            UserAchievement userAchievement = await _mimoDbContext.UserAchievements
                                              .Where(ua => ua.UserId == userId && ua.AchievementId == achievementDto.Id)
                                              .FirstOrDefaultAsync();

            userAchievement.Progress += 1;

            if (userAchievement.Progress == achievementDto.RequiredCount)
            {
                userAchievement.Completed = true;
            }

            await _mimoDbContext.SaveChangesAsync();

            return(HttpStatusCode.OK);
        }
        private async Task <HttpStatusCode> UpdateCSharpCourseAchievement(AchievementDto achievementDto, int userId, int lessonId, List <UserAchievementDto> userAchievementDtos)
        {
            await HandleNewUserAchievement(achievementDto, userId, userAchievementDtos);

            var course = await _mimoDbContext.Lessons
                         .Where(l => l.Id == lessonId)
                         .Select(l => new
            {
                l.ChapterFk.CourseId,
                l.ChapterFk.CourseFk.CourseName
            })
                         .FirstOrDefaultAsync();

            if (course.CourseName == "C#")
            {
                return(await UpdateCourseAchievement(achievementDto, userId, lessonId, course.CourseId, userAchievementDtos));
            }

            return(HttpStatusCode.OK);
        }
Ejemplo n.º 15
0
        public IResult AddAchievement(AchievementDto achievementDto)
        {
            using WordBookContext db = new();
            if (db.Achievements.Any(a => a.AchievementTypeId == achievementDto.AchievementTypeId))
            {
                return(new ErrorResult(Messages.AchievementAlreadyExists));
            }
            Achievement addedAchievement = new()
            {
                AchievementId     = 0,
                UserId            = achievementDto.UserId,
                AchievementTypeId = achievementDto.AchievementTypeId,
                Score             = achievementDto.Score,
                UpdatedAt         = System.DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString()
            };

            db.Achievements.Add(addedAchievement);
            db.SaveChanges();
            return(new SuccessResult(Messages.AchievementAdded));
        }
        private async Task <HttpStatusCode> UpdateCourseAchievement(AchievementDto achievementDto, int userId, int lessonId, int courseId, List <UserAchievementDto> userAchievementDtos)
        {
            int[] lessonIds = await _mimoDbContext.Lessons
                              .Where(l => l.ChapterFk.CourseId == courseId)
                              .Select(c => c.Id)
                              .ToArrayAsync();

            int[] completedLessonIds = await _mimoDbContext.UserLessons
                                       .Where(ul => ul.UserId == userId)
                                       .Select(ul => ul.LessonId)
                                       .ToArrayAsync();

            int[] uncompletedLessonIds = lessonIds.Where(l => completedLessonIds.All(c => c != l)).ToArray();

            if (uncompletedLessonIds.Length == 0)
            {
                return(await _userAchievementsService.ProgressUserAchievement(achievementDto, userId));
            }

            return(HttpStatusCode.OK);
        }
        private async Task <HttpStatusCode> HandleNewUserAchievement(AchievementDto achievementDto, int userId, List <UserAchievementDto> userAchievementDtos)
        {
            UserAchievementDto userAchievementDto = userAchievementDtos
                                                    .Where(uad => uad.AchievementId == achievementDto.Id)
                                                    .FirstOrDefault();

            if (userAchievementDto == null)
            {
                PostUserAchievementDto postUserAchievementDto = new PostUserAchievementDto
                {
                    AchievementId = achievementDto.Id,
                    Completed     = false,
                    Progress      = 0,
                    UserId        = userId
                };

                return(await _userAchievementsService.PostUserAchievement(postUserAchievementDto));
            }

            return(HttpStatusCode.OK);
        }
Ejemplo n.º 18
0
 public async Task GoToAchievementScreenAsync(AchievementDto achievement)
 {
     await GoToScreenAsync(new AchievementScreen(context, achievement));
 }
Ejemplo n.º 19
0
 /// <summary>
 /// 添加成就
 /// </summary>
 /// <param name="dto"></param>
 /// <returns></returns>
 public JsonResult DoAdd(AchievementDto dto)
 {
     dto.creator = TaskWebSession.id;
     return(achievementManager.AddAchievement(dto) ?
            resultManager.SuccessResult() : resultManager.FailureResult());
 }
Ejemplo n.º 20
0
 public bool DeleteAchievement(AchievementDto dto)
 {
     return(false);
 }
Ejemplo n.º 21
0
 public bool EditAchievement(AchievementDto dto)
 {
     return(false);
 }
Ejemplo n.º 22
0
        public IActionResult Insert([FromBody] AchievementDto achievementDto)
        {
            var achievement = Mapper.Map <Achievement>(achievementDto);

            return(Ok(_achievementService.Insert(achievement)));
        }
Ejemplo n.º 23
0
 private void ReportProgress(AchievementDto achievement, int score)
 {
     AchievementsManager.Instance.LocalUnlock(achievement);
     ReportScore(score);
     CheckLevelUp(true);
 }
Ejemplo n.º 24
0
 public AchievementScreen(MainContext context, AchievementDto achievement)
 {
     InitializeComponent();
     BindingContext = new AchievementScreenViewModel(context, achievement);
 }
Ejemplo n.º 25
0
 public AchievementScreenViewModel(MainContext context, AchievementDto achievement) : base(context)
 {
     Achievement = achievement;
 }