コード例 #1
0
        public JsonResult GetStepList(String ObserveId)
        {
            ObservesModel observesModel = ObserveServiceManager.GetObserveById(ObserveId);

            if (observesModel.Users.Id == User.Identity.GetUserId())
            {
                List <StepsModel>          modelList = StepServiceManager.GetStepListByObserveId(ObserveId);
                List <StepListOutputModel> newList   = new List <StepListOutputModel>();

                foreach (StepsModel item in modelList)
                {
                    string StringMethod    = null;
                    string StringSetHeader = null;

                    if (item.Method == 1)
                    {
                        StringMethod = "GET";
                    }
                    else if (item.Method >= 2)
                    {
                        StringMethod = "POST";
                    }

                    if (item.SetHeader == 1)
                    {
                        StringSetHeader = "Yes";
                    }
                    else if (item.SetHeader == 0)
                    {
                        StringSetHeader = "No";
                    }
                    else if (item.SetHeader == 2)
                    {
                        StringSetHeader = "Pre";
                    }

                    StepListOutputModel newModel = new StepListOutputModel()
                    {
                        Id        = item.Id,
                        Priority  = item.Order.GetValueOrDefault(),
                        Url       = item.Url,
                        Method    = StringMethod,
                        SetHeader = StringSetHeader
                    };

                    newList.Add(newModel);
                }

                return(Json(newList));
            }
            else
            {
                return(Json(JsonConvert.DeserializeObject("{ 'Status' = 'Unauthorized Access' }")));
            }
        }
コード例 #2
0
        public ActionResult Modify(string id)
        {
            if (Request.Browser.IsMobileDevice)
            {
                return(RedirectToAction("ModifyM"));
            }

            ObservesModel              model          = ObserveServiceManager.GetObserveById(id);
            List <StepsModel>          oriList        = StepServiceManager.GetStepListByObserveId(id);
            List <PCMethodsModel>      methodList     = PCMethodServiceManager.GetPCMethodList().OrderBy(e => e.Name).ToList();
            List <StepListOutputModel> newList        = new List <StepListOutputModel>();
            List <PCMethodOutputModel> PCMethodOutput = new List <PCMethodOutputModel>();

            foreach (StepsModel item in oriList)
            {
                string StringMethod    = null;
                string StringSetHeader = null;

                if (item.Method == 1)
                {
                    StringMethod = "GET";
                }
                else if (item.Method >= 2)
                {
                    StringMethod = "POST";
                }

                if (item.SetHeader == 1)
                {
                    StringSetHeader = "Yes";
                }
                else if (item.SetHeader == 0)
                {
                    StringSetHeader = "No";
                }
                else if (item.SetHeader == 2)
                {
                    StringSetHeader = "Pre";
                }
                StepListOutputModel newModel = new StepListOutputModel()
                {
                    Id        = item.Id,
                    Priority  = item.Order.GetValueOrDefault(),
                    Url       = item.Url,
                    Method    = StringMethod,
                    SetHeader = StringSetHeader
                };
                newList.Add(newModel);
            }

            foreach (PCMethodsModel item in methodList)
            {
                PCMethodOutputModel newModel = new PCMethodOutputModel()
                {
                    Id   = item.Id,
                    Name = item.Name
                };

                PCMethodOutput.Add(newModel);
            }

            try
            {
                ObserveOutputModel output = new ObserveOutputModel()
                {
                    Id       = model.Id,
                    Name     = model.Name,
                    Status   = model.Status.GetValueOrDefault(),
                    Interval = model.Interval.GetValueOrDefault(),
                    StepList = newList,
                    PCMethod = PCMethodOutput
                };

                return(View(output));
            } catch (NullReferenceException e)
            {
                return(RedirectToAction("Index", "Observe"));
            }
        }