public async Task <ActionResult> Delete(short id)
        {
            try
            {
                var model = new WorkflowStateViewModel();
                model.Id = id;

                //Call API Provider - Transaction
                string apiUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_DELETE);
                var    result = await APIProvider.Authorize_DynamicTransaction <WorkflowStateViewModel, 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> Edit(byte id)
        {
            try
            {
                var data = new WorkflowStateViewModel();
                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.Authorize_Get <WorkflowStateViewModel>(_userSession.BearerToken, controllerName + strUrl, APIConstant.API_Resource_CMS, ARS.Get);

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

                    ViewBag.WorkflowId = workflow;
                    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;
            }
        }
        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;
            }
        }
示例#4
0
        public async Task <WorkflowStateViewModel> GetById(byte id)
        {
            List <string> list = new List <string> {
                "Id", "WorkflowId"
            };
            var para = APIProvider.APIDefaultParameter(list, id, 0);

            var source = await _workflowStateRepo.SingleQuery(para);

            WorkflowStateViewModel dest = Mapper.Map <WorkflowStateViewModel>(source);

            return(dest);
        }
        public async Task <ActionResult> Edit(WorkflowStateViewModel model)
        {
            if (ModelState.IsValid)
            {
                //Call API Provider
                string strUrl = APIProvider.APIGenerator(controllerName, APIConstant.ACTION_UPDATE);
                var    result = await APIProvider.Authorize_DynamicTransaction <WorkflowStateViewModel, bool>(model, _userSession.BearerToken, strUrl, APIConstant.API_Resource_CMS, ARS.IgnoredARS);

                if (result)
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.SUCCESS, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.SUCCESS));
                }
                else
                {
                    TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.ERROR, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.ERROR));
                }
                return(RedirectToAction("Index"));
            }
            else
            {
                TempData["Alert"] = ApplicationGenerator.RenderResult(ApplicationGenerator.TypeResult.FAIL, ApplicationGenerator.GeneralActionMessage(APIConstant.ACTION_UPDATE, ApplicationGenerator.TypeResult.FAIL));
                return(View());
            }
        }
示例#6
0
        public async Task <bool> Transaction(WorkflowStateViewModel workflowSateModel, char action)
        {
            var obj = Mapper.Map <WorkflowStateEdit>(workflowSateModel);

            return(await _workflowStateRepo.Transaction(obj, action));
        }
        // 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));
        }