Esempio n. 1
0
        public async Task OnGetAsync(long?id, long?pid)
        {
            if (id.HasValue)
            {
                Dto = await _service.GetByIdAsync(id.Value);

                if (Dto == null)
                {
                    throw new VinoDataNotFoundException();
                }
                if (Dto.ParentId.HasValue)
                {
                    Parents = await _service.GetParentsAsync(Dto.ParentId.Value);
                }
                ViewData["Mode"] = "Edit";
            }
            else
            {
                Dto = new FunctionDto();
                if (pid.HasValue)
                {
                    Dto.ParentId = pid.Value;
                    Parents      = await _service.GetParentsAsync(pid.Value);
                }
                else
                {
                    Dto.ParentId = null;
                }
                ViewData["Mode"] = "Add";
            }
        }
        public override async Task<IActionResult> GetFunctionAsync([FromRoute, Required] Guid functionId)
        {
            if (functionId == Guid.Empty)
                return BadRequest();

            var function = await functionService.GetByIdAsync(functionId);

            if(function == null)
                return NotFound();

            return Ok(function);
        }
Esempio n. 3
0
        public async Task <IActionResult> Edit(long?id, long?pid)
        {
            if (id.HasValue)
            {
                //编辑
                var module = await _service.GetByIdAsync(id.Value);

                if (module == null)
                {
                    throw new VinoDataNotFoundException("无法取得数据!");
                }
                if (module.ParentId.HasValue)
                {
                    ViewBag.Parents = await _service.GetParentsAsync(module.ParentId.Value);
                }
                ViewData["Mode"] = "Edit";
                return(View(module));
            }
            else
            {
                //新增
                FunctionDto dto = new FunctionDto();
                dto.IsEnable = true;
                if (pid.HasValue)
                {
                    dto.ParentId    = pid.Value;
                    ViewBag.Parents = await _service.GetParentsAsync(pid.Value);
                }
                else
                {
                    dto.ParentId = null;
                }
                ViewData["Mode"] = "Add";
                return(View(dto));
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> GetById(string id)
        {
            var model = _mapper.Map <Function, FunctionViewModel>(await _functionService.GetByIdAsync(id));

            return(new OkObjectResult(model));
        }