コード例 #1
0
ファイル: SchedulesController.cs プロジェクト: jose2a/ADYC
        // PUT api/<controller>/5
        public IHttpActionResult PutSchedules(int offeringId, [FromBody] ScheduleListDto form)
        {
            if (ModelState.IsValid)
            {
                var schedulesInDb = _scheduleService.FindByOfferingId(offeringId);

                if (schedulesInDb == null || schedulesInDb.Count() == 0)
                {
                    return(BadRequest());
                }

                try
                {
                    Mapper.Map(form.Schedules, schedulesInDb);

                    _scheduleService.UpdateRange(schedulesInDb);

                    return(Ok());
                }
                catch (ArgumentException ae)
                {
                    ModelState.AddModelError("", ae.Message);
                }
            }

            return(BadRequest(ModelState));
        }
コード例 #2
0
ファイル: SchedulesController.cs プロジェクト: jose2a/ADYC
        public IHttpActionResult PostSchedules(int offeringId, [FromBody] ScheduleListDto form)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var schedules = Mapper.Map <IEnumerable <ScheduleDto>, IEnumerable <Schedule> >(form.Schedules);
                    var offering  = _offeringService.Get(offeringId);

                    _scheduleService.AddRange(schedules);

                    var scheduleListDto = GetScheduleListDto(offeringId, offering, schedules);

                    return(Created(new Uri(scheduleListDto.Url), scheduleListDto));
                }
                catch (ArgumentException ae)
                {
                    ModelState.AddModelError("", ae.Message);
                }
                catch (PreexistingEntityException pee)
                {
                    ModelState.AddModelError("", pee.Message);
                }
            }

            return(BadRequest(ModelState));
        }
コード例 #3
0
        public ScheduleListViewModel(ScheduleListDto schedulesListDto)
        {
            OfferingId = schedulesListDto.Offering.Id;
            Offering   = schedulesListDto.Offering;
            Schedules  = schedulesListDto.Schedules.ToList();

            IsNew = !(Schedules
                      .Count(s => s.StartTime.HasValue && s.EndTime.HasValue) > 0);
            IsCurrentTerm = schedulesListDto.Offering.Term.IsCurrentTerm;
        }
コード例 #4
0
        public async Task <ActionResult> SaveSchedules(ScheduleListViewModel form)
        {
            ModelState.Remove("Offering.Title");
            ModelState.Remove("Offering.Location");
            ModelState.Remove("Offering.Term");

            if (ModelState.IsValid)
            {
                try
                {
                    form.Schedules = form.Schedules.Where(s => s.StartTime.HasValue && s.EndTime.HasValue).ToList();

                    var scheduleList = new ScheduleListDto
                    {
                        Schedules = form.Schedules
                    };

                    if (form.IsNew)
                    {
                        scheduleList.Offering = await _offeringRepository.GetOfferingById(form.OfferingId);

                        await _scheduleRepository.PostScheduleList(scheduleList);
                    }
                    else
                    {
                        await _scheduleRepository.PutScheduleList(form.OfferingId, scheduleList);
                    }

                    AddPageAlerts(ViewHelpers.PageAlertType.Success, "Your changes have been saved succesfully.");

                    return(RedirectToAction("Schedules", new { offeringId = form.OfferingId }));
                }
                catch (BadRequestException bre)
                {
                    AddErrorsFromAdycHttpExceptionToModelState(bre, ModelState);
                }
            }

            var days = GetDayEnumViewModelList();

            form.Offering = await _offeringRepository.GetOfferingById(form.OfferingId);

            form.Schedules = GetScheduleList(form.OfferingId, form.Schedules.ToList(), days);
            form.Days      = days;

            // Add properties to layout
            AddPageHeader("Schedules", "Schedules for this offering");

            AddBreadcrumb("Offerings (Terms)", Url.Action("Index"));
            AddBreadcrumb("Offerings (List)", Url.Action("View", new { TermId = form.Offering.TermId }));
            AddBreadcrumb("Schedules", "");

            return(View("Schedules", form));
        }
コード例 #5
0
    private void HandleAddedSchedules(ScheduleListDto inboundSchedulesDto, bool allSchedules)
    {
        ScheduleDto[] inboundSchedules = inboundSchedulesDto.GetSchedules();
        Array.Sort(inboundSchedules, (schedOne, schedTwo) => {
            try
            {
                string[] firstDateTimePartition = schedOne.GetDate().Replace("/", " ").Replace(":", " ").Split(' ');
                int firstDateMonth  = int.Parse(firstDateTimePartition[0]);
                int firstDateDay    = int.Parse(firstDateTimePartition[1]);
                int firstDateYear   = int.Parse(firstDateTimePartition[2]);
                int firstDateHour   = int.Parse(firstDateTimePartition[3]);
                int firstDateMinute = int.Parse(firstDateTimePartition[4]);
                int firstDateSecond = int.Parse(firstDateTimePartition[5]);
                DateTime firstDate  = new DateTime(firstDateYear, firstDateMonth, firstDateDay, firstDateHour, firstDateMinute, firstDateSecond);
                string[] secondDateTimePartition = schedTwo.GetDate().Replace("/", " ").Replace(":", " ").Split(' ');

                int secondDateMonth  = int.Parse(secondDateTimePartition[0]);
                int secondDateDay    = int.Parse(secondDateTimePartition[1]);
                int secondDateYear   = int.Parse(secondDateTimePartition[2]);
                int secondDateHour   = int.Parse(secondDateTimePartition[3]);
                int secondDateMinute = int.Parse(secondDateTimePartition[4]);
                int secondDateSecond = int.Parse(secondDateTimePartition[5]);
                DateTime secondDate  = new DateTime(secondDateYear, secondDateMonth, secondDateDay, secondDateHour, secondDateMinute, secondDateSecond);
                return(secondDate.CompareTo(firstDate));
            }
            //It's possible one of the dates have foreign characters, so let's just return 0 here
            catch (Exception e) {
                return(0);
            }
        });

        if (!allSchedules)
        {
            inboundSchedules = inboundSchedules.Where(schedule => schedule.GetScheduleType().Trim().ToLower().Equals(selectedScheduleType.text.Trim().ToLower())).ToArray();
        }
        //We add one here for esthetics, it's nice to have a bit of padding at the bottom of the list
        ResizeCanvas(inboundSchedules.Length + 1);
        DestroyOldSchedules();
        scheduleDtos = inboundSchedules;
        GameObject previousSchedule = scheduleAnchor;

        foreach (ScheduleDto dto in inboundSchedules)
        {
            GameObject newSchedule = CreateNewScheduleObject(previousSchedule, dto);
            scheduleList.Add(newSchedule);
            previousSchedule = newSchedule;
        }
    }
コード例 #6
0
ファイル: ADYCBasedApiController.cs プロジェクト: jose2a/ADYC
        protected ScheduleListDto GetScheduleListDto(int offeringId, Offering offering,
                                                     IEnumerable <Schedule> schedules)
        {
            var scheduleListDto = new ScheduleListDto
            {
                Url       = UrlResoucesUtil.GetBaseUrl(Request, "Offerings") + offeringId + "/Schedules",
                Schedules = schedules
                            .Select(s =>
                {
                    return(GetScheduleDto(s));
                })
            };

            scheduleListDto.Offering                       = Mapper.Map <Offering, OfferingDto>(offering);
            scheduleListDto.Offering.Url                   = UrlResoucesUtil.GetBaseUrl(Request, "Offerings") + offeringId;
            scheduleListDto.Offering.Professor.Url         = UrlResoucesUtil.GetBaseUrl(Request, "Professors") + offering.ProfessorId;
            scheduleListDto.Offering.Course.Url            = UrlResoucesUtil.GetBaseUrl(Request, "Courses") + offering.CourseId;
            scheduleListDto.Offering.Course.CourseType.Url = UrlResoucesUtil.GetBaseUrl(Request, "CourseTypes") + offering.Course.CourseTypeId;
            scheduleListDto.Offering.Term.Url              = UrlResoucesUtil.GetBaseUrl(Request, "Terms") + offering.TermId;

            return(scheduleListDto);
        }
コード例 #7
0
    IEnumerator SendScheduleGetAllRequest(string uri, Action <ScheduleListDto> handleSchedulesLoadFinished)
    {
        UnityWebRequest request = new UnityWebRequest(uri, APIConstants.GET_METHOD);

        request.downloadHandler = new DownloadHandlerBuffer();

        SetRequestHeaders(request);

        SetInfoText(APIConstants.LOADING_SCHED);
        yield return(request.SendWebRequest());

        byte[]          result           = request.downloadHandler.data;
        ScheduleListDto dto              = JsonConvert.DeserializeObject <ScheduleListDto>(Encoding.UTF8.GetString(result));
        bool            retrievalSuccess = false;

        if (dto != null && dto.GetSchedules().Length > 0)
        {
            retrievalSuccess = true;
        }

        handleSchedulesLoadFinished(dto);
        HandleAllScheduleGetResponse(request, retrievalSuccess);
    }
コード例 #8
0
 public void HandleSelectedAddedSchedules(ScheduleListDto inboundSchedulesDto)
 {
     HandleAddedSchedules(inboundSchedulesDto, false);
 }
コード例 #9
0
 public void HandleAllAddedSchedules(ScheduleListDto inboundSchedulesDto)
 {
     HandleAddedSchedules(inboundSchedulesDto, true);
 }