public async Task <IActionResult> AddMealScheduleEntry([FromBody] MealScheduleEntryCreationVM mealScheduleCreation) { if (!ModelState.IsValid) { return(NotFound()); } var userId = new Guid(User.Identity.Name); var entryId = await _mealScheduleService.AddMealScheduleEntryAsync(userId, mealScheduleCreation); if (entryId == null) { return(Unauthorized()); } return(Ok(entryId)); }
public async Task <Guid?> AddMealScheduleEntryAsync(Guid userId, MealScheduleEntryCreationVM newMealScheduleEntry) { var dbMealScheduleEntry = _mapper.Map <MealScheduleEntry>(newMealScheduleEntry); dbMealScheduleEntry.UserId = userId; bool addedSuccessfully = await _mealScheduleRepository.AddAsync(dbMealScheduleEntry); if (!addedSuccessfully) { return(null); } var checkNumberOfMealUsesTask = _achievementService.CheckForNumberOfMealUsesAsync(dbMealScheduleEntry.MealId); var checkConsequentUpdatesTask = _achievementService.CheckForConsequentScheduleUpdatesAsync(userId); await Task.WhenAll(checkNumberOfMealUsesTask, checkConsequentUpdatesTask); return(dbMealScheduleEntry.Id); }