protected override void ExecuteRequest(HttpContext context) { (bool isOk, User user) = CheckClaimsForUser(Request, context, _userRepository); if (!isOk || user == null) { return; } PhysicalActivityEntry PAEntry = _physicalActivitiesEntryRepository.Get(Request.Id).GetAwaiter().GetResult().FirstOrDefault(); if (PAEntry == null) { context.Response.StatusCode = StatusCodes.Status400BadRequest; context.Response.WriteAsync("Could not find the physical activity entry, please check body data sanity"); return; } if (!_physicalActivitiesEntryRepository.Delete(Request.Id).GetAwaiter().GetResult()) { context.Response.StatusCode = StatusCodes.Status400BadRequest; context.Response.WriteAsync("Could not remove the food entry"); } else { context.Response.StatusCode = StatusCodes.Status200OK; } }
protected override void ExecuteRequest(HttpContext context) { (bool isOk, User user) = CheckClaimsForUser(Request, context, _userRepository); if (!isOk || user == null) { return; } PhysicalActivityEntry PAEntry = _physicalActivitiesEntryRepository.Get(Request.Id).GetAwaiter().GetResult().FirstOrDefault(); if (PAEntry == null) { context.Response.StatusCode = StatusCodes.Status204NoContent; return; } PAEntry.DatetimeStart = Request.NewDateTimeStart; PAEntry.DatetimeEnd = Request.NewDateTimeEnd; PAEntry = _physicalActivitiesEntryRepository.Update(PAEntry).GetAwaiter().GetResult(); if (PAEntry == null) { context.Response.StatusCode = StatusCodes.Status400BadRequest; context.Response.WriteAsync("Could not update the given physical activity entry, please check body data sanity"); } else { context.Response.StatusCode = StatusCodes.Status200OK; } }
protected override void ExecuteRequest(HttpContext context) { (bool isOk, User user) = CheckClaimsForUser(Request, context, _userRepository); if (!isOk || user == null) { return; } PhysicalActivity PA = _physicalActivitiesRepository.GetPhysicalActivity(Request.Name); if (PA == null) { context.Response.StatusCode = StatusCodes.Status204NoContent; return; } PhysicalActivityEntry PAEntry = _physicalActivitiesEntryRepository.Insert(new PhysicalActivityEntry() { UserId = user.Id, PhysicalActivitiesId = PA.Id, DatetimeStart = DateTime.Parse(Request.DateTimeStart), DatetimeEnd = DateTime.Parse(Request.DateTimeEnd) }).GetAwaiter().GetResult(); if (PAEntry != null) { // update all quests based on datas var quests = _questRepository.Get(user, _questTypeRepository, QuestState.InProgress).GetAwaiter().GetResult(); foreach (var quest in quests) { var questHandler = QuestHandlers.Create(quest, user, _questTypeRepository); questHandler.Update(PhysicalActivityQuestHandler.PHYSICAL_ACTIVTY_KEY, "1"); _questRepository.Update(quest).GetAwaiter().GetResult(); } string PAEntryJson = JsonSerializer.Serialize(PAEntry); context.Response.StatusCode = StatusCodes.Status200OK; context.Response.WriteAsync(PAEntryJson).GetAwaiter().GetResult(); } else { context.Response.StatusCode = StatusCodes.Status204NoContent; } }