예제 #1
0
        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var id   = (int)value;
            var name = "";

            using (var db = new Arthur.App.AppContext())
            {
                name = db.Users.FirstOrDefault(o => o.Id == id)?.Name;
            }
            if (string.IsNullOrEmpty(name))
            {
                name = "Unknown";
            }
            return(name);
        }
예제 #2
0
 public Result Create(User user)
 {
     try
     {
         using (var db = new Arthur.App.AppContext())
         {
             if (db.Users.Count(r => r.Name == user.Name) > 0)
             {
                 return(new Result(string.Format("系统中已存在名为{0}的角色!", user.Name)));
             }
             db.Users.Add(new App.Model.User()
             {
                 Name = user.Name
             });
             db.SaveChanges();
         }
         return(Result.Success);
     }
     catch (Exception ex)
     {
         return(new Result(ex.Message));
     }
 }
예제 #3
0
 public Result Create(Role role)
 {
     try
     {
         using (var db = new Arthur.App.AppContext())
         {
             if (db.Roles.Count(r => r.Name == role.Name) > 0)
             {
                 return(new Result(string.Format("系统中已存在名为{0}的角色!", role.Name)));
             }
             db.Roles.Add(new App.Model.Role()
             {
                 Level = role.Level, Name = role.Name
             });
             db.SaveChanges();
         }
         Arthur.App.Business.Logging.AddOplog(string.Format("新增角色[{0}]", role.Name), App.Model.OpType.创建);
         return(Result.Success);
     }
     catch (Exception ex)
     {
         return(new Result(ex.Message));
     }
 }