public async Task <ActionResult> Delete(byte id)
        {
            try
            {
                //Call API Provider
                string strUrl = APIProvider.APIGenerator(this, this.RouteData.Values["action"].ToString(), id);
                var    model  = await APIProvider.Get <SliderViewModel>(controllerName + strUrl);

                string apiUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_DELETE);
                var    result = await APIProvider.Authorize_DynamicTransaction <SliderViewModel, bool>(model, _userSession.BearerToken, apiUrl, APIConstant.API_Resource_CMS, ARS.IgnoredARS);

                if (result)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, "Xóa thành công");
                }
                else
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, "Xóa không thành công");
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                return(View());
            }
        }
        public async Task <ActionResult> Delete(byte id)
        {
            try
            {
                string apicheckIsUsedUrl = controllerName + "/CheckIsUsed/" + id;
                var    checkIsused       = await APIProvider.Get <bool>(apicheckIsUsedUrl);

                if (!checkIsused)
                {
                    var model = new WorkflowViewModel();
                    model.Id = id;

                    //Call API Provider - Transactions
                    string apiUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_DELETE);
                    var    result = await APIProvider.Authorize_DynamicTransaction <WorkflowViewModel, bool>(model, _userSession.BearerToken, apiUrl, APIConstant.API_Resource_CMS, ARS.IgnoredARS);
                }
                else
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.ERROR, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_DELETE, ApplicationGenerator.TypeResult.ISUSED));
                }

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
                return(View());
            }
        }
        public async Task <ActionResult> Edit(byte id)
        {
            var data = new WorkflowViewModel();

            try
            {
                if (!await APIProvider.Authorization(_userSession.BearerToken, ARS.Edit))
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.FuntionType.Account, APIConstant.ACTION_UPDATE);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //Call API Provider
                    string strUrl = APIProvider.APIGenerator(this, this.RouteData.Values["action"].ToString(), id);
                    data = await APIProvider.Get <WorkflowViewModel>(controllerName + strUrl);

                    return(View(data));
                }
            }
            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: 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;
            }
        }
        public async Task <ActionResult> Create(FeatureViewModel model, HttpPostedFileBase fileUpload)
        {
            try
            {
                if (fileUpload == null)
                {
                    ModelState.AddModelError("Image", "Vui lòng chọn hình ảnh");
                }

                if (ModelState.IsValid)
                {
                    if (fileUpload != null)
                    {
                        //model.Image = fileUpload.FileName;
                        string imgName = "";
                        FileManagement.UploadImage(fileUpload, ValueConstant.IMAGE_FEATURE_PATH, ref imgName);
                        model.Image = imgName;
                    }

                    //Call API Provider
                    string strUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_INSERT);
                    var    result = await APIProvider.Authorize_DynamicTransaction <FeatureViewModel, 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 feature = new FeatureModel();
                    feature.lstFeatureViewModel = await APIProvider.Get <List <FeatureViewModel> >(controllerName);

                    feature.FeatureViewModel = model;

                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    return(View("Index", feature));
                }
            }
            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 <JsonResult> CheckExist(string name, byte id)
        {
            //Call API Provider - Get data
            string apiUrl = APIProvider.APIGenerator(controllerName, new List <string> {
                "id", "name"
            }, false, id, name.Trim());
            var isExist = await APIProvider.Get <bool>(apiUrl);

            return(Json(!isExist, JsonRequestBehavior.AllowGet));
        }
        // GET: Setting
        public async Task <ActionResult> Index()
        {
            try
            {
                controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                var model = await APIProvider.Get <SettingViewModel>(controllerName + "/" + GlobalVariables.Id_Configuration, APIConstant.API_Resource_CORE);

                if (model == null)
                {
                    model = new SettingViewModel
                    {
                        Id         = GlobalVariables.Id_Configuration,
                        Membership = true
                    };
                }
                var roles = new List <RoleViewModel>
                {
                    new RoleViewModel {
                        Id = 1, Name = "Chưa sử dụng"
                    }
                };
                ViewBag.Roles = roles;
                if (model?.Keyword != null)
                {
                    ViewBag.Keywords = model.Keyword;
                }

                var startTime           = TimeSpan.FromMinutes(model.AppointmentStartTime);
                var fromStartTimeString = startTime.ToString("hh':'mm");
                model.AppointmentStartTimeString = fromStartTimeString;

                var endTime           = TimeSpan.FromMinutes(model.AppointmentEndTime);
                var fromEndTimeString = endTime.ToString("hh':'mm");
                model.AppointmentEndTimeString = fromEndTimeString;

                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)
        {
            var model = new GalleryViewModel();

            try
            {
                if (!await APIProvider.Authorization(_userSession.BearerToken, ARS.Edit))
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.FuntionType.Account, APIConstant.ACTION_UPDATE);
                    return(RedirectToAction("Index"));
                }
                else
                {
                    //Call API Provider
                    string strUrl = APIProvider.APIGenerator(this, this.RouteData.Values["action"].ToString(), id);
                    model = await APIProvider.Authorize_Get <GalleryViewModel>(_userSession.BearerToken, controllerName + strUrl, APIConstant.API_Resource_CMS, ARS.Get);

                    ViewBag.Img = Path.Combine(Path.Combine(ValueConstant.IMAGE_GALLERY_PATH, model.Id), model.Img);

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

                    departments         = (departments == null ? new List <DepartmentViewModel>() : departments);
                    ViewBag.Departments = departments;

                    TempData["Departments"] = departments;

                    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(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(CategoryViewModel model, HttpPostedFileBase fileUpload)
        {
            try
            {
                ModelState["ParentId"].Errors.Clear();

                if (ModelState.IsValid)
                {
                    if (fileUpload != null)
                    {
                        model.Image = fileUpload.FileName;
                        string name = string.Empty;
                        FileManagement.UploadImage(fileUpload, ValueConstant.IMAGE_CATEGORY_PATH, ref name);
                    }

                    //Call API Provider
                    string strUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_INSERT);
                    var    result = await APIProvider.Authorize_DynamicTransaction <CategoryViewModel, 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 categories = new CategoriesModel();
                    if (TempData["Data"] != null)
                    {
                        categories.lstCategoryViewModel = (List <CategoryViewModel>)TempData["Data"];
                    }
                    else
                    {
                        var list = await APIProvider.Get <List <CategoryViewModel> >(controllerName);

                        categories.lstCategoryViewModel = list;
                    }
                    categories.CategoryViewModel = model;

                    ViewBag.Categories = categories.lstCategoryViewModel;
                    TempData["Alert"]  = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_INSERT, ApplicationGenerator.TypeResult.FAIL));
                    return(View("Index", categories));
                }
            }
            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;
            }
        }