public static void RegisterNewTeam(int ownerId, Team team) { using (var context = new ProbnikContext()) { context.Teams.Add(team); context.SaveChanges(); } }
public static void RegisterNewUser(User user) { using (var context = new ProbnikContext()) { if (user.isValid == true) { context.Users.Add(user); context.SaveChanges(); } } }
public static void CreateNewPerson(Person person) { using (var context = new ProbnikContext()) { if (person.PESEL != null && !context.People.Any(p => p.PESEL == person.PESEL)) { context.People.Add(person); context.SaveChanges(); } } }
public static bool ConnectUserToPerson(int userId, int personId, string key, ConnectionType connectionType) { using (var context = new ProbnikContext()) { var person = context.People.Single(p => p.Id == personId); if (person.ConnectionKey == key) { var connection = new UserToPersonConnection(userId, person.Id.Value, connectionType); context.UserToPersonConnections.Add(connection); person.GenerateNewKey(); context.SaveChanges(); } } return(false); }
private static void Test() { var context = new ProbnikContext(); User user = new User(); user.Login = "******"; user.Email = "*****@*****.**"; user.IsAdmin = true; user.Password = "******"; //context.Users.AddOrUpdate(user); Person person = new Person("Wiktor", "Matecki", "18-08-1997"); // UserToPersonConnection upc = new UserToPersonConnection(); // upc.User = user; // upc.Person = person; // // person.Users.Add(upc); //context.People.AddOrUpdate(person); //context.SaveChanges(); Methodology HS = new Methodology(); HS.Name = "Harcerze Starsi"; //context.Methodologies.AddOrUpdate(HS); Methodology w = new Methodology(); w.Name = "Wędrownicy"; //context.Methodologies.AddOrUpdate(w); Patron patron = new Patron(); patron.Person = person; Team b = new Team(); b.Name = "Berserk"; b.Methodologies.Add(HS); b.Patrons.Add(patron); context.Teams.AddOrUpdate(b); Team e = new Team(); e.Name = "Emilki"; e.Methodologies.Add(w); context.Teams.AddOrUpdate(e); //context.SaveChanges(); //HS = context.Methodologies.First(m => m.Name == "Harcerze Starsi"); TaskContent task1 = new TaskContent(); task1.Content = "Wyzwanie sportowe"; task1.TaskNumber = 1; var task2 = new TaskContent() { Content = "Wyzwanie duchowe", TaskNumber = 2 }; ChallangeType challengeType = new ChallangeType(); challengeType.Methodologies.Add(HS); challengeType.Name = "Odkrywca"; challengeType.Tasks.Add(task1); challengeType.Tasks.Add(task2); context.ChallangeTypes.Add(challengeType); context.SaveChanges(); //var unit = new UnitOfWork(context); //var p = unit.People.Get(0); //var c = new UserToPersonConnection(); //unit.Users.Get(0); }