Beispiel #1
0
        public IActionResult Post([FromBody] sys_menu value)
        {
            var oldSysMenu = _sysMenuRpt.FindBy(f => f.MenuName == value.MenuName);

            if (oldSysMenu.Any())
            {
                return(BadRequest(string.Concat(value.MenuName, "已经存在。")));
            }
            value.CreatedAt = DateTime.Now;
            value.UpdatedAt = DateTime.Now;
            value.IsValid   = true;

            _sysMenuRpt.Add(value);
            using (var tran = _context.Database.BeginTransaction())
            {
                try
                {
                    _sysMenuRpt.Commit();
                    this.SetMenuRoles(value);
                    tran.Commit();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    tran.Rollback();
                    return(new BadRequestResult());;
                }
            }
            return(new OkObjectResult(value));
        }