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;
            }
        }
Esempio n. 2
0
        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;
            }
        }