コード例 #1
0
        public void ProcessRequest(HttpContext context)
        {
            HttpContextBase        ctx    = new HttpContextWrapper(context);
            SchedulerContextHelper helper = GetContextHelper(ctx);

            string command = GetCommand(ctx);

            ViewType currentView = GetView(ctx);

            ctx.SetCurrentViewType(currentView);

            IClient currentUser = helper.CurrentUser();

            string redirectUrl;

            var util = SchedulerUtility.Create(Provider);

            helper.AppendLog($"ReservationController.ProcessRequest: url = {ctx.Request.Url}");

            try
            {
                ctx.Session.Remove("ErrorMessage");

                if (command == "ReservationAction")
                {
                    redirectUrl = GetReservationAction(ctx);
                }
                else
                {
                    IReservationItem rsv;
                    IResource        res;

                    switch (command)
                    {
                    case "ChangeHourRange":
                        string range = ctx.Request.QueryString["Range"];

                        helper.AppendLog($"ReservationController.ProcessRequest: range = {range}");

                        if (range == "FullDay")
                        {
                            ctx.SetDisplayDefaultHours(false);
                        }
                        else
                        {
                            ctx.SetDisplayDefaultHours(true);
                        }

                        redirectUrl = util.GetReservationViewReturnUrl(currentView);
                        break;

                    case "NewReservation":
                        var canCreate = CanCreateNewReservation(ctx);

                        helper.AppendLog($"ReservationController.ProcessRequest: canCreate = {canCreate}");

                        if (canCreate)
                        {
                            redirectUrl = SchedulerUtility.GetReservationReturnUrl(ctx.Request.SelectedPath(), ctx.Request.SelectedLocationPath(), 0, ctx.Request.SelectedDate(), GetReservationTime(ctx), currentView);
                        }
                        else
                        {
                            redirectUrl = util.GetReservationViewReturnUrl(currentView);
                        }
                        break;

                    case "ModifyReservation":
                        rsv = helper.GetReservationWithInvitees();
                        res = helper.GetResourceTreeItemCollection().GetResource(rsv.ResourceID);
                        var currentDate = ctx.Request.SelectedDate();
                        var currentTime = GetReservationTime(ctx);
                        redirectUrl = SchedulerUtility.GetReservationReturnUrl(PathInfo.Create(res), ctx.Request.SelectedLocationPath(), rsv.ReservationID, currentDate, currentTime, currentView);
                        break;

                    case "DeleteReservation":
                        rsv = helper.GetReservationWithInvitees();
                        Reservations.Create(Provider, DateTime.Now).Delete(rsv, currentUser.ClientID);

                        redirectUrl = util.GetReservationViewReturnUrl(currentView);
                        break;

                    default:
                        throw new NotImplementedException($"Command not implemented: {command}");
                    }
                }
            }
            catch (Exception ex)
            {
                string errmsg = ex.Message;

                ctx.Session["ErrorMessage"] = errmsg;

                helper.AppendLog($"ReservationController.ProcessRequest: errmsg = {errmsg}");

                try
                {
                    redirectUrl = util.GetReservationViewReturnUrl(currentView);
                }
                catch
                {
                    redirectUrl = string.Empty;
                }
            }

            if (string.IsNullOrEmpty(redirectUrl))
            {
                redirectUrl = "~";
            }

            helper.AppendLog($"ReservationController.ProcessRequest: redirectUrl = {redirectUrl}");

            ctx.Response.Redirect(redirectUrl);
        }