Exemplo n.º 1
0
        public async Task CreateAchievement(AchievementCreateDTO Achievement, CancellationToken Cancel)
        {
            if (ModelsValidator.AchievementIsValid((Mapper.Map <AchievementUpdateDTO>(Achievement))))
            {
                var _Achievement = Mapper.Map <Achievement>(Achievement);
                _Achievement.Id = new Guid();
                await UnitOfWork.AchievementRepository.Create(_Achievement, Cancel);

                await UnitOfWork.SaveChangesAsync(Cancel);
            }
            else
            {
                throw new ArgumentException();
            }
        }
Exemplo n.º 2
0
        public async Task UpdateAchievement(Guid Id, AchievementUpdateDTO Achievement, CancellationToken Cancel)
        {
            if (ModelsValidator.AchievementIsValid(Achievement))
            {
                if ((await UnitOfWork.AchievementRepository
                     .DbSet.FirstOrDefaultAsync(item => item.Id == Id, Cancel)) == null)
                {
                    throw new ArgumentNullException();
                }

                var _Achievement = await UnitOfWork.AchievementRepository.DbSet.FirstOrDefaultAsync(item => item.Id == Id, Cancel);

                Mapper.Map(Achievement, _Achievement);
                UnitOfWork.AchievementRepository.Update(_Achievement);
                await UnitOfWork.SaveChangesAsync(Cancel);
            }
            else
            {
                throw new ArgumentException();
            }
        }