예제 #1
0
        public IActionResult SwitchDay([FromBody] SwitchDayParameter switchDayParameter)
        {
            if (switchDayParameter == null || switchDayParameter.TrainingDayKey == null)
            {
                return(BadRequest());
            }
            try
            {
                TrainingDayKey trainingDayKey  = switchDayParameter.TrainingDayKey;
                int            switchDayOfWeek = switchDayParameter.SwitchDayOfWeek;

                if (trainingDayKey == null || string.IsNullOrWhiteSpace(trainingDayKey.UserId) ||
                    trainingDayKey.Year == 0 || trainingDayKey.WeekOfYear == 0 || trainingDayKey.DayOfWeek < 0 || trainingDayKey.DayOfWeek > 6 ||
                    switchDayOfWeek < 0 || switchDayOfWeek > 6 || SessionUserId != trainingDayKey.UserId)
                {
                    return(BadRequest());
                }

                _trainingDaysService.SwitchDayOnTrainingDay(trainingDayKey.UserId, trainingDayKey.Year, trainingDayKey.WeekOfYear, trainingDayKey.DayOfWeek, switchDayOfWeek);
                return(new OkObjectResult(true)); //bool
            }
            catch (Exception exception)
            {
                return(BadRequest(new WebApiException("Error", exception)));
            };
        }
        internal static async Task <bool> SwitchDayOfTrainingDay(TrainingDayKey trainingDayKey, int switchDayOfWeek)
        {
            if (trainingDayKey == null)
            {
                return(false);
            }

            var switchDayParameter = new SwitchDayParameter()
            {
                TrainingDayKey  = trainingDayKey,
                SwitchDayOfWeek = switchDayOfWeek
            };

            return(await HttpConnector.Instance.PostAsync <SwitchDayParameter, bool>("Api/TrainingDays/SwitchDay", switchDayParameter));
        }