public ActionResult Create([Bind(Include = "Journal,Coffee")] CoffeeViewModel cvm, int PrivacyList) { if (ModelState.IsValid) { // Create journal object and add to database Journal j = new Journal() { AuthorID = 1, // TODO: use Identity to set this property Date = DateTime.Now, Description = cvm.Journal.Description, JType = "co", Location = cvm.Journal.Location, Maker = cvm.Journal.Maker, PrivacyType = PrivacyList, Rating = cvm.Journal.Rating, Title = cvm.Journal.Title }; db.Journals.Add(j); db.SaveChanges(); // Create pairing coffee object and add to database Coffee c = new Coffee() { FoodPairing = cvm.Coffee.FoodPairing, JournalID = j.JournalID, Origin = cvm.Coffee.Origin, RoastType = cvm.Coffee.RoastType }; db.Coffees.Add(c); db.SaveChanges(); return RedirectToAction("Index"); // TODO: make sure this links to appropriate page. Consider the user's profile. } ViewBag.PrivacyList = GetPrivacyList(null); return View(cvm); }
protected override void Seed(TheConnoisseurContext context) { Author a1 = new Author() { AuthorID = 1, AvatarPath = "", // Empty for now City = "Eugene", DateCreated = new DateTime(2016, 1, 30, 12, 23, 45), Email = "*****@*****.**", EmailConfirm = "*****@*****.**", FavItem = "Heart of Darkness by the Wandering Goat", FirstName = "Brody", LastName = "Case", Password = "******", PasswordConfirm = "Test9!", PrivacyType = 1, State = "OR", Tagline = "When it's bitter, it is best", Username = "******", }; Author a2 = new Author() { AuthorID = 2, AvatarPath = "", // Empty for now City = "Portland", DateCreated = new DateTime(2016, 2, 3, 19, 12, 40), Email = "*****@*****.**", EmailConfirm = "*****@*****.**", FavItem = "Old Raspuin", FirstName = "Will", LastName = "Dewald", Password = "******", PasswordConfirm = "Test9!", PrivacyType = 1, State = "OR", Tagline = "More rain, please.", Username = "******", }; Journal j1 = new Journal() { AuthorID = 1, Date = new DateTime(2016, 2, 8, 16, 23, 4), Description = "With the earthy tones of a well roasted Sumatran coffee, the blackness of this cup was deep like my soul until together the taste and sensation brought my alive. For the light of heart, use less bean to water than normal.", ImagePath = "", JournalID = 1, JType = "co", Location = "At home", Maker = "Wander Goat", PrivacyType = 1, Rating = 4, Title = "Heart of Darkness", }; Coffee c1 = new Coffee() { CoffeeID = 2, FoodPairing = "None", JournalID = 1, Origin = "Sumatra", RoastType = "Dark roast" }; Privacy p1 = new Privacy() { PrivacyID = 1, Name = "public" }; Privacy p2 = new Privacy() { PrivacyID = 2, Name = "private" }; Privacy p3 = new Privacy() { PrivacyID = 3, Name = "friends only" }; context.Privacies.Add(p1); context.Privacies.Add(p2); context.Privacies.Add(p3); context.Authors.Add(a1); context.Authors.Add(a2); context.Journals.Add(j1); context.Coffees.Add(c1); base.Seed(context); }