Exemplo n.º 1
0
        public JsonResult SavePri(int Id, IList <int> Ids)
        {
            var tag = roleFunctionPrivoder.BeginTransaction(() =>
            {
                roleFunctionPrivoder.Delete(c => c.RoleId == Id);
                foreach (var item in Ids)
                {
                    roleFunctionPrivoder.Add(new RoleFunctionInfo()
                    {
                        FnId   = item,
                        RoleId = Id
                    });
                }
            });

            var js = new AjaxResult();

            if (tag)
            {
                js.Success = true;
                js.Message = "操作成功";
            }
            else
            {
                js.Success = false;
                js.Message = "操作失败";
            }
            return(Json(js));
        }
        public async Task <IActionResult> Delete(int id)
        {
            var response = new SingleModelResponse <FunctionResource>();

            try
            {
                var entity = await GetFunctionWithRelated(id);

                if (entity == null)
                {
                    response.DidError     = true;
                    response.ErrorMessage = "Input could not be found.";
                    return(response.ToHttpResponse());
                }

                await _roleFunctionService.Delete(entity.RoleFunctions.ToList());

                await _functionRepository.DeleteAsync(entity.Id);

                response.Model   = _mapper.Map <Function, FunctionResource>(entity);
                response.Message = "The record was deleted successfully";
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }