public void Init(string email, IRepository repository) { if (!string.IsNullOrEmpty(email)) { User = repository.GetUser(email); } }
public bool CreateMessage(User.Message instance) { if (instance.MessageId == 0) { Db.Messages.Add(instance); Db.SaveChanges(); return true; } return false; }
public bool CreateUser(User.User instance) { instance.Birthdate = new DateTime(1950, 1, 3); if (instance.UserId == 0) { Db.Users.Add(instance); Db.SaveChanges(); return true; } return false; }
public bool UpdateMessage(User.Message instance) { User.Message cache = Db.Messages.FirstOrDefault(p => p.MessageId == instance.MessageId); if (cache != null) { cache.Text = instance.Text; cache.Topic = instance.Topic; cache.ReceiverId = instance.ReceiverId; cache.SenderId = instance.SenderId; Db.SaveChanges(); return true; } return false; }
public bool UpdateUser(User.User instance) { Models.User.User dbUser = GetUser(instance.UserId); if (dbUser != null) { var a = this.MemberwiseClone(); Type t = instance.GetType(); foreach (PropertyInfo info in t.GetProperties()) { if (info.CanWrite) { var value = info.GetValue(instance); if (value != null) info.SetValue(dbUser, value, null); } } Db.SaveChanges(); return true; } return false; }