public async Task <ActionResult> Create()
        {
            if (!await APIProvider.Authorization(_userSession.BearerToken, ARS.Insert))
            {
                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.FuntionType.UserProfile, APIConstant.ACTION_INSERT);
                return(RedirectToAction("Index"));
            }
            else
            {
                string   search = string.Empty;
                UserType type   = EnumUserConstants.UserType.ISDOCTOR;
                string   apiUrl = APIProvider.APIGenerator("User", new List <string> {
                    nameof(search), nameof(type)
                }, true, search, type);
                var list = await APIProvider.Authorize_Get <List <UserViewModel> >(_userSession.BearerToken, apiUrl, APIConstant.API_Resource_CORE, ARS.IgnoredARS);

                if (list == null)
                {
                    ViewBag.User = ApplicationGenerator.GetObject <UserViewModel>();
                }
                else
                {
                    ViewBag.User = list;
                }

                return(View());
            }
        }
        // GET: Survey
        public async Task <ActionResult> Index()
        {
            try
            {
                var model = await APIProvider.Get <List <SurveyModel> >(ControllerName, APIConstant.API_Resource_CORE);

                if (model == null)
                {
                    model = ApplicationGenerator.GetObject <List <SurveyModel> >();
                }
                return(View(model));
            }
            catch (HttpException ex)
            {
                Logger.LogError(ex);
                int statusCode = ex.GetHttpCode();
                if (statusCode == 401)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(FuntionType.Department, APIConstant.ACTION_ACCESS);
                    return(new HttpUnauthorizedResult());
                }

                throw ex;
            }
        }
        // GET: Schedule
        public async Task <ActionResult> Index(ScheduleMultipleViewModel data)
        {
            try
            {
                byte   type   = (byte)EnumUserConstants.UserType.ISDOCTOR;
                string search = "";
                string apiUrl = APIProvider.APIGenerator(controllerUser, new List <string> {
                    nameof(search), nameof(type)
                }, true, search, type);
                var doctorList = await APIProvider.Authorize_Get <List <UserViewModel> >(_userSession.BearerToken, apiUrl, APIConstant.API_Resource_CORE, ARS.Get);

                if (doctorList == null)
                {
                    doctorList = ApplicationGenerator.GetObject <List <UserViewModel> >();
                }
                ViewBag.Users = doctorList;

                if (data.ScheduleFilter == null)
                {
                    data.ScheduleFilter = new ScheduleFilter();
                }
                var param = data.ScheduleFilter;
                //Call API Provider
                if (param.Start == DateTime.MinValue && param.End == DateTime.MinValue)
                {
                    param.Start = DateTime.Now;
                    param.End   = DateTime.Now;
                }
                controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                string apiUrlSchedule = APIProvider.APIGenerator(controllerName, new List <string> {
                    nameof(param.UserId),
                    nameof(param.Start), nameof(param.End)
                }, true, param.UserId, param.Start.ToString("yyyy-MM-dd"), param.End.ToString("yyyy-MM-dd"));
                var schedule = await APIProvider.Authorize_Get <List <ScheduleViewModel> >(_userSession.BearerToken, apiUrlSchedule, APIConstant.API_Resource_CORE, ARS.Get);

                if (schedule.Count == 0)
                {
                    schedule = new List <ScheduleViewModel>();
                }

                ViewBag.Schedule = schedule;

                var schedules = new ScheduleMultipleViewModel();
                var model     = schedules.ScheduleFilter;
                return(View(model));
            }
            catch (HttpException ex)
            {
                Logger.LogError(ex);
                int statusCode = ex.GetHttpCode();
                if (statusCode == 401)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(FuntionType.Department, APIConstant.ACTION_ACCESS);
                    return(new HttpUnauthorizedResult());
                }

                throw ex;
            }
        }
        public async Task <ActionResult> Create(WorkflowStateViewModel model)
        {
            try
            {
                if (model.WorkflowId == 0)
                {
                    ModelState.AddModelError("WorkflowId", "Vui lòng chọn workflow");
                }
                if (ModelState.IsValid)
                {
                    //Call API Provider
                    string strUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_INSERT);
                    var    result = await APIProvider.Authorize_DynamicTransaction <WorkflowStateViewModel, bool>(model, _userSession.BearerToken, strUrl, APIConstant.API_Resource_CMS, ARS.Insert);

                    if (result)
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.SUCCESS));
                    }
                    else
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var workflowStates = new WorkflowStatesModel();
                    if (TempData["Data"] != null)
                    {
                        workflowStates.lstWorkflowStateViewModel = (List <WorkflowStateViewModel>)TempData["Data"];
                    }

                    if (workflowStates.lstWorkflowStateViewModel == null)
                    {
                        workflowStates.lstWorkflowStateViewModel = ApplicationGenerator.GetObject <List <WorkflowStateViewModel> >();
                    }
                    workflowStates.WorkflowStateViewModel = model;

                    ViewBag.WorkflowId = await APIProvider.Authorize_Get <List <WorkflowViewModel> >(_userSession.BearerToken, controllerWorkflow, APIConstant.API_Resource_CMS, ARS.Get);

                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    return(View("Index", workflowStates));
                }
            }
            catch (HttpException ex)
            {
                Logger.LogError(ex);
                int statusCode = ex.GetHttpCode();
                if (statusCode == 401)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(FuntionType.Department, APIConstant.ACTION_ACCESS);
                    return(new HttpUnauthorizedResult());
                }

                throw ex;
            }
        }
        public async Task <ActionResult> Create(DepartmentViewModel model, HttpPostedFileBase fileUpload)
        {
            if (!await APIProvider.Authorization(_userSession.BearerToken, ARS.Insert))
            {
                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.FuntionType.Department, APIConstant.ACTION_INSERT);
                return(RedirectToAction("Index"));
            }
            else
            {
                if (ModelState.IsValid)
                {
                    if (fileUpload != null)
                    {
                        model.Img = fileUpload.FileName;
                    }

                    //Call API Provider
                    string strUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_INSERT);
                    var    result = await APIProvider.Authorize_DynamicTransaction <DepartmentViewModel, bool>(model, _userSession.BearerToken, strUrl, APIConstant.API_Resource_CORE, ARS.Insert);

                    if (result)
                    {
                        if (fileUpload != null)
                        {
                            FileManagement.UploadImage(fileUpload, ValueConstant.IMAGE_DEPARTMENT_PATH);
                        }

                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.SUCCESS));
                    }
                    else
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var department = new DepartmentModel();
                    department.lstDepartmentViewModel = (List <DepartmentViewModel>)TempData["Data"];

                    if (department.lstDepartmentViewModel == null)
                    {
                        department.lstDepartmentViewModel = ApplicationGenerator.GetObject <List <DepartmentViewModel> >();
                    }
                    department.DepartmentViewModel = model;

                    //TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(ValueConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    return(View("Index", department));
                }
            }
        }
        private async Task <UserViewModel> GetPhysician(string physicianId)
        {
            var id     = physicianId;
            var apiUrl = APIProvider.APIGenerator("User", new List <string> {
                nameof(id)
            }, false, id);
            var doctor = await APIProvider.Authorize_Get <UserViewModel>(_userSession.BearerToken, apiUrl, APIConstant.API_Resource_CORE, ARS.Get);

            if (doctor == null)
            {
                doctor = ApplicationGenerator.GetObject <UserViewModel>();
            }
            return(doctor);
        }
        /// <summary>
        /// Get doctor by Id
        /// </summary>
        /// <param name="doctorId"></param>
        /// <returns></returns>
        private async Task <DoctorProfileViewModel> GetDoctorDetail(string doctorId)
        {
            var    token  = _userSession.BearerToken;
            string id     = doctorId;
            string apiUrl = APIProvider.APIGenerator(controllerDoctor, new List <string> {
                nameof(id)
            }, false, id);
            var doctor = await APIProvider.Authorize_Get <DoctorProfileViewModel>(token, apiUrl, APIConstant.API_Resource_CORE, ARS.Detail);

            if (doctor == null)
            {
                doctor = ApplicationGenerator.GetObject <DoctorProfileViewModel>();
            }
            return(doctor);
        }
        //get userId current login
        //private string GetUserId()
        //{
        //    var identity = Thread.CurrentPrincipal.Identity;
        //    if (identity == null && HttpContext.User != null)
        //    {
        //        identity = HttpContext.User.Identity;
        //    }
        //    return identity.GetUserId();
        //}

        /// <summary>
        /// Get List of doctor
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        private async Task <List <UserViewModel> > GetListDoctor(string search)
        {
            var    token  = _userSession.BearerToken;
            string action = "GetUserHaveScheduleExamine";
            string apiUrl = APIProvider.APIGenerator(controllerUser, action, new List <string> {
                nameof(search)
            }, true, search);
            var list = await APIProvider.Authorize_Get <List <UserViewModel> >(token, apiUrl, APIConstant.API_Resource_CORE, ARS.Get);

            if (list == null)
            {
                list = ApplicationGenerator.GetObject <List <UserViewModel> >();
            }

            return(list);
        }
        public async Task <ActionResult> Create(ScheduleMultipleViewModel param)
        {
            if (ModelState.IsValid)
            {
                controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                string strUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_INSERT);

                var model = param.CreateScheduleViewModel;
                model.Start = DateTime.Parse(model.StartDate + " " + model.StartTime);
                model.End   = DateTime.Parse(model.StartDate + " " + model.EndTime);
                model.Color = string.Empty;
                if (param.CreateScheduleViewModel.UserId == null)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.ERROR, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    return(RedirectToAction("Index"));
                }

                var result = await APIProvider.Authorize_DynamicTransaction <CreateScheduleViewModel, int>(model, _userSession.BearerToken, strUrl, APIConstant.API_Resource_CORE, ARS.Insert);

                if (result > 0)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.SUCCESS));
                }
                else
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                }
                return(RedirectToAction("Index"));
            }
            else
            {
                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                byte   type   = (byte)EnumUserConstants.UserType.ISDOCTOR;
                string search = "";
                string apiUrl = APIProvider.APIGenerator(controllerUser, new List <string> {
                    nameof(search), nameof(type)
                }, true, search, type);
                var doctorList = await APIProvider.Authorize_Get <List <UserViewModel> >(_userSession.BearerToken, apiUrl, APIConstant.API_Resource_CORE, ARS.Get);

                if (doctorList == null)
                {
                    doctorList = ApplicationGenerator.GetObject <List <UserViewModel> >();
                }
                ViewBag.Users = doctorList;
                return(View("Index", param));
            }
        }
        // GET: UserProfile
        public async Task <ActionResult> Index(string userId)
        {
            try
            {
                // Get list user set into ViewBag
                string   search     = string.Empty;
                UserType type       = EnumUserConstants.UserType.ISDOCTOR;
                string   apiUserUrl = APIProvider.APIGenerator("User", new List <string> {
                    nameof(search), nameof(type)
                }, true, search, type);
                var list = await APIProvider.Authorize_Get <List <UserViewModel> >(_userSession.BearerToken, apiUserUrl, APIConstant.API_Resource_CORE, ARS.Get);

                if (list == null)
                {
                    ViewBag.User = ApplicationGenerator.GetObject <UserViewModel>();
                }
                else
                {
                    ViewBag.User = list;
                }

                // Get list user profile by userId
                string apiUrl = "User/GetUserProfile?userId=" + userId;
                var    model  = await APIProvider.Authorize_Get <List <UserProfileViewModel> >(_userSession.BearerToken, apiUrl, APIConstant.API_Resource_CORE, ARS.Get);

                if (model == null)
                {
                    model = new List <UserProfileViewModel>();
                }
                return(View(model));
            }
            catch (HttpException ex)
            {
                Logger.LogError(ex);
                int statusCode = ex.GetHttpCode();
                if (statusCode == 401)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(FuntionType.Department, APIConstant.ACTION_ACCESS);
                    return(new HttpUnauthorizedResult());
                }

                throw ex;
            }
        }
        public async Task <ActionResult> Edit(string id)
        {
            if (!await APIProvider.Authorization(_userSession.BearerToken, ARS.Edit))
            {
                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.FuntionType.Survey, APIConstant.ACTION_UPDATE);
                return(RedirectToAction("Index"));
            }
            else
            {
                var strUrl = APIProvider.APIGenerator(this, this.RouteData.Values["action"].ToString(), id);
                var model  = await APIProvider.Authorize_Get <SurveyModel>(_userSession.BearerToken, ControllerName + strUrl, APIConstant.API_Resource_CORE, ARS.IgnoredARS);

                if (model == null)
                {
                    model = ApplicationGenerator.GetObject <SurveyModel>();
                }
                if (model.SurveyQuestionsModel == null)
                {
                    model.SurveyQuestionsModel = new List <SurveyQuestionsModel>();
                }
                return(View(model));
            }
        }
        public async Task <ActionResult> Edit(string userId, string tabCode)
        {
            if (!await APIProvider.Authorization(_userSession.BearerToken, ARS.Edit))
            {
                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.FuntionType.UserProfile, APIConstant.ACTION_UPDATE);
                return(RedirectToAction("Index"));
            }
            else
            {
                // Get list user set into ViewBag
                string   search     = string.Empty;
                UserType type       = EnumUserConstants.UserType.ISDOCTOR;
                string   apiUserUrl = APIProvider.APIGenerator("User", new List <string> {
                    nameof(search), nameof(type)
                }, true, search, type);
                var list = await APIProvider.Authorize_Get <List <UserViewModel> >(_userSession.BearerToken, apiUserUrl, APIConstant.API_Resource_CORE, ARS.IgnoredARS);

                if (list == null)
                {
                    ViewBag.User = ApplicationGenerator.GetObject <UserViewModel>();
                }
                else
                {
                    ViewBag.User = list;
                }

                // Get user profile by tabcode and userId
                string apiUrl = "User/GetUserProfileByTabCode?userId=" + userId + "&tabCode=" + tabCode;
                var    model  = await APIProvider.Authorize_Get <UserProfileViewModel>(_userSession.BearerToken, apiUrl, APIConstant.API_Resource_CORE, ARS.IgnoredARS);

                if (model == null)
                {
                    model = new UserProfileViewModel();
                }
                return(View(model));
            }
        }
        public async Task <ActionResult> Create(SliderViewModel model, HttpPostedFileBase fileUpload)
        {
            try
            {
                if (fileUpload == null)
                {
                    ModelState.AddModelError("Image", "Vui lòng chọn hình");
                }
                if (ModelState.IsValid)
                {
                    if (fileUpload != null)
                    {
                        model.Image = fileUpload.FileName;
                        string imgName = "";

                        int[] demiSize = LayoutGuide.GetDefaultSize(Image_ModuleName.Slider);
                        if (demiSize == null)
                        {
                            FileManagement.UploadImage(fileUpload, ValueConstant.IMAGE_SLIDER_PATH, ref imgName);
                        }
                        else
                        {
                            FileManagement.UploadImage(fileUpload, ValueConstant.IMAGE_SLIDER_PATH, ref imgName, demiSize[0], demiSize[1]);
                        }

                        model.Image = imgName;
                    }

                    //Call API Provider
                    string strUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_INSERT);
                    var    result = await APIProvider.Authorize_DynamicTransaction <SliderViewModel, bool>(model, _userSession.BearerToken, strUrl, APIConstant.API_Resource_CMS, ARS.Insert);

                    if (result)
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.SUCCESS));
                    }
                    else
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var slider = new SliderModel();
                    if (TempData["Data"] == null)
                    {
                        slider.lstSliderViewModel = await APIProvider.Authorize_Get <List <SliderViewModel> >(_userSession.BearerToken, controllerName, APIConstant.API_Resource_CMS, ARS.Get);
                    }
                    else
                    {
                        slider.lstSliderViewModel = (List <SliderViewModel>)TempData["Data"];
                    }

                    if (slider.lstSliderViewModel == null)
                    {
                        slider.lstSliderViewModel = ApplicationGenerator.GetObject <List <SliderViewModel> >();
                    }
                    slider.SliderViewModel = model;

                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    return(View("Index", slider));
                }
            }
            catch (HttpException ex)
            {
                Logger.LogError(ex);
                int statusCode = ex.GetHttpCode();
                if (statusCode == 401)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(FuntionType.Department, APIConstant.ACTION_ACCESS);
                    return(new HttpUnauthorizedResult());
                }

                throw ex;
            }
        }
        public async Task <ActionResult> Create(GalleryViewModel model, HttpPostedFileBase fileUpload)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.Id = Guid.NewGuid().ToString();

                    if (fileUpload != null)
                    {
                        string imgName = "";
                        FileManagement.UploadImage(fileUpload, Path.Combine(ValueConstant.IMAGE_GALLERY_PATH, model.Id), ref imgName);
                        model.Img = imgName;
                    }

                    //Call API Provider
                    string strUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_INSERT);
                    var    result = await APIProvider.Authorize_DynamicTransaction <GalleryViewModel, bool>(model, _userSession.BearerToken, strUrl, APIConstant.API_Resource_CMS, ARS.Insert);

                    if (result)
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.SUCCESS));
                    }
                    else
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    }
                    return(RedirectToAction("Index"));
                }
                else
                {
                    var department = new GalleryModel();
                    department.lstGallery = (List <GalleryViewModel>)TempData["Galleries"];

                    var departments = (List <DepartmentViewModel>)TempData["Departments"];
                    if (departments == null)
                    {
                        string strUrl = APIProvider.APIGenerator("Department", new List <string> {
                            "type"
                        }, true, "available");
                        departments = await APIProvider.Get <List <DepartmentViewModel> >(strUrl, APIConstant.API_Resource_CORE);
                    }
                    ViewBag.Departments = departments;


                    if (department.lstGallery == null)
                    {
                        department.lstGallery = ApplicationGenerator.GetObject <List <GalleryViewModel> >();
                    }
                    department.Gallery = model;

                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    return(RedirectToAction("Index", department));
                }
            }
            catch (HttpException ex)
            {
                Logger.LogError(ex);
                int statusCode = ex.GetHttpCode();
                if (statusCode == 401)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(FuntionType.Department, APIConstant.ACTION_ACCESS);
                    return(new HttpUnauthorizedResult());
                }

                throw ex;
            }
        }
        public async Task <ActionResult> Create(UserProfileViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string strUrl = APIProvider.APIGenerator("User", "UserProfileTransaction", APIConstant.ACTION_INSERT);
                    var    token  = _userSession.BearerToken;

                    var result = await APIProvider.Authorize_DynamicTransaction <UserProfileViewModel, int>(model, token, strUrl, APIConstant.API_Resource_Authorize);

                    if (result > 0)
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.SUCCESS));
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                        string   search = string.Empty;
                        UserType type   = EnumUserConstants.UserType.ISDOCTOR;
                        string   apiUrl = APIProvider.APIGenerator("User", new List <string> {
                            nameof(search), nameof(type)
                        }, true, search, type);
                        var list = await APIProvider.Authorize_Get <List <UserViewModel> >(token, apiUrl, APIConstant.API_Resource_CORE, ARS.IgnoredARS);

                        if (list == null)
                        {
                            ViewBag.User = ApplicationGenerator.GetObject <UserViewModel>();
                        }
                        else
                        {
                            ViewBag.User = list;
                        }

                        return(View());
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError(ex);
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.ERROR, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.ERROR));
                    throw ex;
                }
            }
            else
            {
                StringBuilder errorBuilder = new StringBuilder();
                foreach (var modelError in ModelState)
                {
                    if (modelError.Value.Errors.Count > 0)
                    {
                        errorBuilder.AppendLine(modelError.Value.Errors[0].ErrorMessage.ToString());
                    }
                }

                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, errorBuilder.ToString());
                string   search = string.Empty;
                UserType type   = EnumUserConstants.UserType.ISDOCTOR;
                string   apiUrl = APIProvider.APIGenerator("User", new List <string> {
                    nameof(search), nameof(type)
                }, true, search, type);
                var list = await APIProvider.Authorize_Get <List <UserViewModel> >(_userSession.BearerToken, apiUrl, APIConstant.API_Resource_CORE, ARS.IgnoredARS);

                if (list == null)
                {
                    ViewBag.User = ApplicationGenerator.GetObject <UserViewModel>();
                }
                else
                {
                    ViewBag.User = list;
                }

                return(View(model));
            }
        }
        // GET: WorkflowState

        public async Task <ActionResult> Index(byte?wId)
        {
            var results = new WorkflowStatesModel();

            try
            {
                //Call API Provider
                controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                var workflow = await APIProvider.Authorize_Get <List <WorkflowViewModel> >(_userSession.BearerToken, controllerWorkflow, APIConstant.API_Resource_CMS, ARS.Get);

                List <WorkflowStateViewModel> list = ApplicationGenerator.GetObject <List <WorkflowStateViewModel> >();
                if (wId.HasValue)
                {
                    results.WorkflowId  = (byte)wId;
                    ViewBag.WorkflowIdx = new SelectList(workflow, "Id", "Name", results.WorkflowId);

                    string apiUrl = APIProvider.APIGenerator(controllerName, "GetByWorkflowId", new List <string> {
                        "id"
                    }, false, wId);
                    list = await APIProvider.Authorize_Get <List <WorkflowStateViewModel> >(_userSession.BearerToken, apiUrl, APIConstant.API_Resource_CMS, ARS.Get);

                    if (list != null && list.Any(a => a.IsFirst == true))
                    {
                        //get workflow navigation
                        apiUrl = APIProvider.APIGenerator(controllerWorkflowNavigate, "GetByWorkflowId", new List <string> {
                            "id"
                        }, false, wId);
                        var wfNavigation = await APIProvider.Authorize_Get <List <WorkflowNavigationViewModel> >(_userSession.BearerToken, apiUrl, APIConstant.API_Resource_CMS, ARS.Get);

                        var listwfNavigation = GetWfNavigation(wfNavigation, list);
                        results.lstWorkflowNavigationViewModel = listwfNavigation;
                    }
                    else
                    {
                        //list = ApplicationGenerator.GetObject<List<WorkflowStateViewModel>>();
                        TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, "Chưa khai báo trạng thái bước khởi tạo.");
                    }
                }
                else
                {
                    ViewBag.WorkflowIdx = new SelectList(workflow, "Id", "Name");
                }

                var data = new WorkflowStateViewModel()
                {
                    Id = 0, IsActive = true
                };
                results.lstWorkflowStateViewModel = list;
                results.WorkflowStateViewModel    = data;

                // Workflow list
                ViewBag.WorkflowId = workflow;
            }
            catch (HttpException ex)
            {
                Logger.LogError(ex);
                int statusCode = ex.GetHttpCode();
                if (statusCode == 401)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(FuntionType.Department, APIConstant.ACTION_ACCESS);
                    return(new HttpUnauthorizedResult());
                }

                throw ex;
            }
            TempData["resultsIndex"] = results;
            return(View(results));
        }