public IHttpActionResult GetEvents(string alias, string fromDate = null)
        {
            if (!paramParser.TryParseNullableDateTime(fromDate, out DateTime? fromDateValue))
            {
                return(errorsFactory.CreateBadRequest(this, fromDate, nameof(fromDate)));
            }

            try
            {
                var events = divisionsService.GetEvents(alias, fromDateValue);

                if (events == null)
                {
                    return(errorsFactory.CreateNotFound(this,
                                                        $"Extracur division '{alias}' was not found"
                                                        ));
                }

                return(Content(HttpStatusCode.OK, events));
            }
            catch (NotSupportedException ex)
            {
                return(errorsFactory.CreateBadRequest(this, ex.Message));
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult IsBusy(string oid, string start, string end)
        {
            if (!Guid.TryParse(oid, out Guid oidValue))
            {
                return(errorsFactory.CreateBadRequest(this, oid, nameof(oid)));
            }

            if (!parseDateTime(start, out DateTime startValue))
            {
                return(errorsFactory.CreateBadRequest(this, start, nameof(start)));
            }

            if (!parseDateTime(end, out DateTime endValue))
            {
                return(errorsFactory.CreateBadRequest(this, end, nameof(end)));
            }

            var contract = classroomsService.IsBusy(oidValue, startValue, endValue);

            if (contract == null)
            {
                return(errorsFactory.CreateNotFound(this,
                                                    $"Classroom oid='{oid}' was not found"
                                                    ));
            }

            return(Content(HttpStatusCode.OK, contract));

            bool parseDateTime(string value, out DateTime result)
            => DateTime.TryParseExact(value, "yyyyMMddHHmm", null, DateTimeStyles.None, out result);
        }
Ejemplo n.º 3
0
        public IHttpActionResult GetClassrooms(
            string oid,
            string seating     = null,
            string minCapacity = null,
            string equipment   = null)
        {
            if (!Guid.TryParse(oid, out Guid oidValue))
            {
                return(errorsFactory.CreateBadRequest(this, oid, nameof(oid)));
            }

            if (!paramParser.TryParseNullableSeating(seating, out Seating? seatingValue))
            {
                return(errorsFactory.CreateBadRequest(this, seating, nameof(seating)));
            }

            if (!paramParser.TryParseNullableInt32(minCapacity, out int?minCapacityValue))
            {
                return(errorsFactory.CreateBadRequest(this, minCapacity, nameof(minCapacity)));
            }

            var equipmentElements = GetEquipmentElements(equipment);

            try
            {
                var classrooms = addressesService.GetClassrooms(
                    oidValue,
                    equipmentElements,
                    seatingValue,
                    minCapacityValue
                    );

                if (classrooms == null)
                {
                    return(errorsFactory.CreateNotFound(this,
                                                        $"Address oid='{oid}' was not found"
                                                        ));
                }

                return(Content(HttpStatusCode.OK, classrooms));
            }
            catch (ArgumentOutOfRangeException ex) when(ex.ParamName == nameof(seating))
            {
                return(errorsFactory.CreateBadRequest(this,
                                                      $"Parameter seating: value '{seating}' is not supported by this API"
                                                      ));
            }
        }
        public IHttpActionResult GetGroups(string id)
        {
            if (!int.TryParse(id, out int idValue))
            {
                return(errorsFactory.CreateBadRequest(this, id, nameof(id)));
            }

            var groups = programsService.GetGroups(idValue);

            if (groups == null)
            {
                return(errorsFactory.CreateNotFound(this,
                                                    $"Study Program id={id} was not found"
                                                    ));
            }

            return(Content(HttpStatusCode.OK, groups));
        }
        public IHttpActionResult GetEvents(string id, TimeTableKindСode timetable = TimeTableKindСode.Unknown)
        {
            if (!int.TryParse(id, out int idValue))
            {
                return(errorsFactory.CreateBadRequest(this, id, nameof(id)));
            }

            var events = groupsService.GetWeekEvents(idValue, timeTableKindCode: timetable);

            if (events == null)
            {
                return(errorsFactory.CreateNotFound(this,
                                                    $"Student group id={id} was not found"
                                                    ));
            }

            return(Content(HttpStatusCode.OK, events));
        }
        public IHttpActionResult NotFound(string path)
        {
            var apiPath = Request.RequestUri.AbsolutePath;
            var message = $"The path was not found: {apiPath}";

            logger.Error(new HttpException(404, message), message);

            return(errorsFactory.CreateNotFound(this, message));
        }
Ejemplo n.º 7
0
        public IHttpActionResult GetProgramsLevels(string alias)
        {
            var programLevels = divisionsService.GetProgramLevels(alias);

            if (programLevels == null)
            {
                return(errorsFactory.CreateNotFound(this,
                                                    $"Division '{alias}' was not found"
                                                    ));
            }

            return(Content(HttpStatusCode.OK, programLevels));
        }
Ejemplo n.º 8
0
        public IHttpActionResult GetEvents(string id, string showNextTerm = null)
        {
            if (!int.TryParse(id, out int idValue))
            {
                return(errorsFactory.CreateBadRequest(this, id, nameof(id)));
            }

            if (!paramParser.TryParseNullableInt32(showNextTerm, out int?showNextTermValue))
            {
                return(errorsFactory.CreateBadRequest(this, showNextTerm, nameof(showNextTerm)));
            }

            var events = educatorsService.GetEvents(idValue, showNextTermValue);

            if (events == null)
            {
                return(errorsFactory.CreateNotFound(this,
                                                    $"Educator id={id} was not found"
                                                    ));
            }

            return(Content(HttpStatusCode.OK, events));
        }