Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            string userName = HttpContext.Current?.User?.Identity?.Name;

            if (string.IsNullOrEmpty(userName))
            {
                userName = "******";
            }

            UserInfo userInfo = new UserInfo()
            {
                UserName = "******"
            };

            if (!string.IsNullOrEmpty(userName))
            {
                var qnomy = new QNomyDataService();
                userInfo = qnomy.GetUserInfo(userName);
            }

            var query = new QueryStringParams(context.Request.Params);

            var dataService = new SchedulerDataService();
            var response    = WrapResponse(() =>
            {
                object data = null;

                switch (query.Action)
                {
                case QueryStringParams.GET_STAGES:
                    data = dataService.GetStages(userInfo.UnitId);
                    break;

                case QueryStringParams.GET_CUSTOMIZEDATA:
                    data = dataService.GetCustomizeData(userInfo.UnitId);
                    break;

                case QueryStringParams.SAVE_CUSTOMIZEDATA:
                    string objJsonCustomize = GetData(context.Request);
                    var dataObjCustomize    = JsonConvert.DeserializeObject <CustomizeData>(objJsonCustomize);
                    data = dataService.SaveCustomizeData(dataObjCustomize);
                    break;

                case QueryStringParams.GET_APPOINTMENTS:
                    //string filterData = GetData(context.Request);
                    //DateFromTo filter = JsonConvert.DeserializeObject<DateFromTo>(filterData);
                    //data = dataService.GetSchedulerEvents(filter.From, filter.To, userInfo.UnitId);
                    data = dataService.GetAppointmentsData(userInfo.UnitId);
                    break;

                case QueryStringParams.SAVE_APPOINTMENT:
                    string objJson = GetData(context.Request);
                    var dataObj    = JsonConvert.DeserializeObject <SchedulerEvent>(objJson);
                    data           = dataService.SaveAppointment(dataObj);
                    break;

                case QueryStringParams.APPOINTMENT_CHANGED:
                    string objJsonApp = GetData(context.Request);
                    var appData       = JsonConvert.DeserializeObject <AppointmentChangedData>(objJsonApp);
                    data = dataService.AppointmentChanged(userInfo.UserId, userInfo.UnitId, appData.PreviousStageId, appData.NextStageId, appData.SchedulerEvent, appData.RouteId);
                    break;

                case QueryStringParams.APPOINTMENT_CANCEL:
                    var eventToCancel = JsonConvert.DeserializeObject <SchedulerEvent>(GetData(context.Request));
                    data = dataService.AppointmentCancel(userInfo.UserId, userInfo.UnitId, eventToCancel);
                    break;

                default:
                    throw new InvalidOperationException($"Action {query.Action} not supported");
                }

                return(data);
            });

            ResponseSetData(context.Response, response);
        }