public async Task<ActionResult> FamilyCreate(FamilyView Family)
		{
			if(!ModelState.IsValid)
			{
				return View(Family);
			}
			var fatherID = Family.Father.RID.ToString();
			var motherID = Family.Mother.RID.ToString();
			var gopherID = Family.Gopher.RID.ToString();
			var father = await db.Users.FirstOrDefaultAsync( c => c.Id == fatherID);
			var mother = await db.Users.FirstOrDefaultAsync( c => c.Id == motherID);
			var gopher = await db.Users.FirstOrDefaultAsync( c => c.Id == gopherID);
			if(father != null)
			{
				if(mother != null)
				{
					if(gopher != null)
					{
						var family = new Family(Family.Name, father, mother, gopher);
						father.Family = family;
						mother.Family = family;
						gopher.Family = family;
						db.Families.Add(family);
						await db.SaveChangesAsync();
					}
				}
			}

			var users = await db.Users.ToListAsync();
			var Retreaters = new Collection<UserView>();
			foreach ( var user in users )
			{
				Boolean result;
				result = ( user.Retreater || user.RetreaterPending ) && user.Family == null;
				if ( result )
				{
					Retreaters.Add( new UserView( user ) );
				}
			}
			ViewBag.Retreaters = new SelectList( Retreaters, "RID", "Name" );
			var families = await db.Families.ToListAsync();
			ICollection<FamilyView> Families = new Collection<FamilyView>();
			foreach ( var family in families )
			{
				Families.Add( new FamilyView( family ) );
			}
			return View( "Families", Families );
		}
Example #2
0
 public FamilyView( Family Family )
     : base(Family.RID)
 {
     this.Name = Family.Name;
     if(Family.Father != null)
         this.Father = new UserView( Family.Father );
     if ( Family.Mother != null )
         this.Mother = new UserView( Family.Mother );
     if ( Family.Gopher != null )
     this.Gopher = new UserView( Family.Gopher );
     this.Children = new Collection<UserView>();
     this.PSite = new Collection<UserView>();
     foreach(var child in Family.Children)
     {
         this.Children.Add(new UserView(child));
     }
     foreach ( var psite in Family.PSite )
     {
         this.Children.Add( new UserView( psite ) );
     }
 }