Пример #1
0
        public JsonResult GetApplicationInfo(string identifier, string email)
        {
            var applicationInfoModel = new ApplicationInfo();

            if (string.IsNullOrEmpty(identifier) && string.IsNullOrEmpty(email))
            {
                applicationInfoModel = new ApplicationInfo
                {
                    Status = ApplicationStatus.PersonItemNotFound
                };

                return(Json(applicationInfoModel, JsonRequestBehavior.AllowGet));
            }

            if (!string.IsNullOrEmpty(identifier))
            {
                var personItem = _service.SearchPeopleByOktaId(identifier);

                //fallback to email verification assuming the persons okta id was updated, can be removed later
                if (personItem == null)
                {
                    personItem = _service.SearchPeopleByEmail(email);
                }

                if (personItem != null)
                {
                    Person personO = new Person();
                    personO.FirstName = personItem.Fields[Constants.Person.Template.Fields.PEOPLE_FIRST_NAME].Value;
                    personO.LastName  = personItem.Fields[Constants.Person.Template.Fields.PEOPLE_LAST_NAME].Value;
                    personO.OktaId    = personItem.Fields[Constants.Person.Template.Fields.OKTA_ID].Value;
                    personO.Email     = personItem.Fields[Constants.Person.Template.Fields.PEOPLE_EMAIL].Value;
                    personO.ItemPath  = personItem.Paths.FullPath;
                    personO.ItemId    = personItem.ID.ToString();


                    var applicationItemId = personItem.Fields[Constants.Person.Template.Fields.PEOPLE_APPLICATION]?.Value;
                    var applicationModel  = _service.GetApplicationModel(applicationItemId);



                    if (applicationModel != null)
                    {
                        if (applicationModel.Completed)
                        {
                            applicationInfoModel = new ApplicationInfo
                            {
                                Status = ApplicationStatus.ApplicationCompleted
                            };
                        }
                        else
                        {
                            var             applicationStepId = applicationModel.Step;
                            ApplicationStep applicationStep   = _service.GetApplicationStepModel(applicationStepId);

                            applicationInfoModel = new ApplicationInfo
                            {
                                Application     = applicationModel,
                                ApplicationStep = applicationStep,
                                Person          = personO,
                                Status          = ApplicationStatus.ApplicationFound
                            };
                        }
                    }
                    else
                    {
                        applicationInfoModel = new ApplicationInfo
                        {
                            Person = personO,
                            Status = ApplicationStatus.ApplicationItemNotFound
                        };
                    }
                }
                else
                {
                    applicationInfoModel = new ApplicationInfo
                    {
                        Status = ApplicationStatus.PersonItemNotFound
                    };
                }
            }
            else
            {
                applicationInfoModel = new ApplicationInfo
                {
                    Status = ApplicationStatus.NotLoggedIn
                };
            }
            return(Json(applicationInfoModel, JsonRequestBehavior.AllowGet));
        }