public ActionResult CreateFamily(CreateFamilyProfile viewModel) { if (!ModelState.IsValid) { ViewBag.Message = "Error. Object is not valid"; return View(viewModel); } var family = new Family() { ParentFirstName = viewModel.ParentFirstName, ParentLastName = viewModel.ParentLastName, Shipping_address = viewModel.Shipping_address, Shipping_city = viewModel.Shipping_city, Shipping_state = viewModel.Shipping_state, Shipping_zipCode = viewModel.Shipping_zipCode, Phone = viewModel.Phone, Email = viewModel.Email }; var child = new Child() { Family_ID = viewModel.Family_ID, Child_FirstName = viewModel.Child_FirstName, Child_LastName = viewModel.Child_LastName, Age = viewModel.Age, Gender = viewModel.Gender }; db.Families.Add(family); db.Children.Add(child); db.SaveChanges(); TempData["Message"] = "Family and Child added successfully"; return RedirectToAction("CreateFamily"); }
private async Task<Family> CreateFamilyModel(RegisterFamilyModel registration) { var family = new Family { ParentFirstName = registration.ParentFirstName, ParentLastName = registration.ParentLastName, Phone = registration.Phone, Email = registration.Email }; if (!registration.IsShippingToCharity) { family.ShippingAddress = new Address { LineOne = registration.ShippingAddress.LineOne, LineTwo = registration.ShippingAddress.LineTwo, City = registration.ShippingAddress.City, State = registration.ShippingAddress.State, PostalCode = registration.ShippingAddress.PostalCode }; } _db.Families.Add(family); await _db.SaveChangesAsync(); return family; }
private async Task<FamilyCredentials> CreateFamilyAccount(Family family) { var username = await GenerateFamilyUsername(family.ParentLastName); var password = GenerateRandomPassword(8); var userStore = new UserStore<WishlistUser>(_db); var userManager = new WishlistUserManager(userStore); await userManager.CreateAsync(new WishlistUser { UserName = username, Email = family.Email, PhoneNumber = family.Phone }, password); var createdUser = await userManager.FindByNameAsync(username); await userManager.AddToRoleAsync(createdUser.Id, "Family"); await userManager.AddClaimAsync(createdUser.Id, new Claim("Family", family.Id.ToString())); return new FamilyCredentials { Username = username, Password = password }; }