public UserDetailViewModel(Core.Models.User user) { User = user; Title = User.Username; UserName = $"@{User.Username}"; UserAvatar = User.Avatar; UserBio = $"{User.Bio}"; }
public static bool Delete(Core.Models.User entity) { try { using (var ctx = new Data.AmstramgramContext()) { var userRepo = new Data.Repositories.UserRepository(ctx, null); userRepo.Delete(entity); return(userRepo.SaveChanges()); } } catch { return(false); } }
public static async Task <Core.Models.User> SignInUser(Core.Models.User user) { try { using (var ctx = new Data.AmstramgramContext()) { var userRepo = new Data.Repositories.UserRepository(ctx, null); var result = await userRepo.SignInUser(user); return(result); } } catch { return(null); } }
public static Core.Models.User Add(Core.Models.User entity) { try { using (var ctx = new Data.AmstramgramContext()) { var userRepo = new Data.Repositories.UserRepository(ctx, null); var result = userRepo.Add(entity); if (!userRepo.SaveChanges()) { return(null); } return(result); } } catch { return(null); } }
public virtual OperationResult UpdateEntity(User user, bool isSave = true) { return UserRepository.Update(user, isSave); }
private static void Method17() { using (var context = new MesContext("MesTest2")) { context.Database.Log = Console.Write; User user = new User { usercode = "65128044", userpwd = "123", AddDate = DateTime.Now, eattribute1 = "123", IsDeleted = false, mdate = DateTime.Now, muser = "******", userdepart = "123", useremail = "123", username = "******", userstat = "123", usertel = "123" } ; context.Users.Add(user); //EntityState state = context.Entry(user).State; //if (state == EntityState.Detached) //{ // context.Entry(user).State = EntityState.Added; //} var students = from u in context.Users.Local where u.usercode == "65128044" select u; var students2 = from u in context.Users where u.usercode == "65128044" select u; students.First(); // context.SaveChanges(); } }
private static void Method08() { for (int i=1;i<11;i++) { User user = new User(); Type t = user.GetType(); foreach (PropertyInfo pi in t.GetProperties()) { object value1 = pi.PropertyType.Name; if (value1.Equals("String")) { pi.SetValue(user, pi.Name + i, null); } if (value1.Equals("DateTime")) { pi.SetValue(user, DateTime.Now, null); } if (value1.Equals("Boolean")) { pi.SetValue(user, false, null); } Console.WriteLine(pi.Name); } // Console.WriteLine(user.usercode); } }
private static void Method07() { User user=new User(); Type t = user.GetType(); user.AddDate = DateTime.Now; user.eattribute1 = "123"; user.IsDeleted = false; user.mdate = DateTime.Now; user.muser = "******"; user.usercode = "65128047"; user.userdepart = "123"; user.useremail = "123"; user.username = "******"; user.userpwd = "123"; user.userstat = "123"; user.usertel = "123"; foreach (PropertyInfo pi in t.GetProperties()) { object value1 = pi.GetValue(user, null);//用pi.GetValue获得值 string name = pi.Name;//获得属性的名字,后面就可以根据名字判断来进行些自己想要的操作 //获得属性的类型,进行判断然后进行以后的操作,例如判断获得的属性是整数 if (value1== null) { continue; } if (value1.GetType() == typeof(string)) { pi.SetValue(user, name, null); } if (value1.GetType() == typeof(DateTime)) { pi.SetValue(user, DateTime.Now, null); } if (value1.GetType() == typeof(bool)) { pi.SetValue(user, false, null); } object value2 = pi.GetValue(user, null);//用pi.GetValue获得值 Console.WriteLine(name + ":" + value2); } }
private static void PrintChangeTrackingInfo(DbContext context, User entity) { var entry = context.Entry(entity); Console.WriteLine(entry.Entity.userpwd); Console.WriteLine("State: {0}", entry.State); Console.WriteLine("\nCurrent Values:"); PrintPropertyValues(entry.CurrentValues); Console.WriteLine("\nOriginal Values:"); PrintPropertyValues(entry.OriginalValues); Console.WriteLine("\nDatabase Values:"); PrintPropertyValues(entry.GetDatabaseValues()); }
//添加 private static void Method03() { DateTime dt = _container.GetExportedValue<IUserFormService>().Users().Select(u => SqlFunctions.GetDate()).First().Value; User user = new User(); user.AddDate = dt; user.eattribute1 = "123"; user.IsDeleted = false; user.mdate = dt; user.muser = "******"; user.usercode = "65128044"; user.userdepart = "123"; user.useremail = "123"; user.username = "******"; user.userpwd = "123"; user.userstat = "123"; user.usertel = "123"; try { Console.WriteLine(_container.GetExportedValue<IUserFormService>().AddEntity(user).Message); } catch(DbEntityValidationException e) { Console.WriteLine(e.EntityValidationErrors.First().ValidationErrors.First().ErrorMessage); } }