public static ReadAchievementModel GetReadAchievementModel(CreateAchievementModel model) { return(new ReadAchievementModel { Id = Guid.NewGuid(), Name = model.Name, Description = model.Description, XP = model.XP, IconId = Guid.NewGuid() }); }
public AchievementModel(CreateAchievementModel model, Guid userId) { AcademicYearId = model.AcademicYearId; AchievementTypeId = model.AchievementTypeId; StudentId = model.StudentId; LocationId = model.LocationId; RecordedById = userId; OutcomeId = model.OutcomeId; CreatedDate = DateTime.Now; Comments = model.Comments; Points = model.Points; }
public async Task <IActionResult> Create([FromBody] CreateAchievementModel model) { return(await ProcessAsync(async() => { var user = await UserService.GetUserByPrincipal(User); var request = new AchievementModel(model, user.Id); await _achievementService.Create(request); return Ok("Achievement created."); }, Permissions.Behaviour.Achievements.EditAchievements)); }
public async Task <IActionResult> Create([FromBody] CreateAchievementModel model) { try { var user = await GetLoggedInUser(); await _behaviourService.CreateAchievement(user.Id.Value, model); return(Ok()); } catch (Exception e) { return(HandleException(e)); } }
public async Task <ReadAchievementModel> AddAchievementAsync(CreateAchievementModel model, CancellationToken cancellationToken) { var achievement = new Achievement() { Name = model.Name, Description = model.Description, XP = model.XP }; achievement.IconId = await _fileService.AddOrUpdateFileByIdAsync(model.Icon, achievement.IconId, cancellationToken); await _achievementRepository.AddAsync(achievement, cancellationToken); await _unitOfWork.SaveChangesAsync(cancellationToken); return(_mapper.Map <ReadAchievementModel>(achievement)); }
public async Task <IActionResult> AddAchievementAsync([FromForm] CreateAchievementModel model, CancellationToken cancellationToken) { var resultValidation = await _createAchievementModelValidator.ValidateAsync(model, cancellationToken); resultValidation.AddToModelState(ModelState, null); if (!ModelState.IsValid) { return(UnprocessableEntity(ModelState)); } var achievement = await _achievementService.AddAchievementAsync(model, cancellationToken); return(CreatedAtRoute( "GetAchievement", new { achievementId = achievement.Id }, achievement)); }
public async Task AddAchievementAsync_CreateAchievementModel_ReturnsReadAchievementModel(CreateAchievementModel model) { //Arrange var expectedValue = AchievementDumbData.GetReadAchievementModel(model); var cancellationToken = new CancellationToken(); _fileService.Setup(x => x.AddOrUpdateFileByIdAsync(It.IsAny <IFormFile>(), It.IsAny <Guid?>(), cancellationToken)).Returns(Task.FromResult(expectedValue.IconId)); _achievementRepository.Setup(x => x.AddAsync(It.IsAny <Achievement>(), cancellationToken)).Returns(Task.FromResult(expectedValue)); _unitOfWork.Setup(x => x.SaveChangesAsync(cancellationToken)).Returns(Task.CompletedTask); // Act var response = await _achievementService.AddAchievementAsync(model, cancellationToken); expectedValue.Id = response.Id; // Assert _fileService.Verify(x => x.AddOrUpdateFileByIdAsync(It.IsAny <IFormFile>(), It.IsAny <Guid?>(), cancellationToken), Times.Once); _achievementRepository.Verify(x => x.AddAsync(It.IsAny <Achievement>(), cancellationToken), Times.Once); _unitOfWork.Verify(x => x.SaveChangesAsync(cancellationToken), Times.Once); response.Should().BeEquivalentTo(expectedValue); }