public ActionResult Create(int id) { Interaction interaction = new Interaction(); Contact contact = db.Contacts.Where(c => c.Id == id).Select(c => c).SingleOrDefault(); ContactInteractionViewModel contactInteraction = new ContactInteractionViewModel(); contactInteraction.Contact = contact; ViewBag.Id = id; contactInteraction.Interaction = interaction; return(View(contactInteraction)); }
public ActionResult Create(ContactInteractionViewModel contactInteraction) { if (ModelState.IsValid) { var recent = DateTime.Today.AddMonths(-3); var contact = contactInteraction.Contact; var description = db.Descriptions.Where(d => d.Id == contact.DescriptionId).Select(d => d).SingleOrDefault(); if (description != null && description.Relationship != null) { var relationship = description.Relationship; switch (relationship) { case "Distant": recent = DateTime.Today.AddMonths(-6); break; case "Familiar": recent = DateTime.Today.AddMonths(-3); break; case "Friend": recent = DateTime.Today.AddMonths(-1); break; case "Close": recent = DateTime.Today.AddDays(-6); break; case "Business Superior": recent = DateTime.Today.AddMonths(-8); break; case "Business Equal": recent = DateTime.Today.AddMonths(-8); break; case "Teacher": recent = DateTime.Today.AddMonths(-8); break; case "Classmate": recent = DateTime.Today.AddMonths(-8); break; default: recent = DateTime.Today.AddMonths(-3); break; } } string goalCode = "5C0R3"; var contactId = contactInteraction.Contact.Id; contactInteraction.Contact = db.Contacts.Where(c => c.Id == contactId).SingleOrDefault(); contactInteraction.Interaction.Contact = contactInteraction.Contact; contactInteraction.Interaction.Contact.Id = contactId; contactInteraction.Interaction.ContactId = contactId; var networkerId = contactInteraction.Interaction.Contact.NetworkerId; var networker = db.Networkers.Where(n => n.Id == networkerId).Select(n => n).SingleOrDefault(); contactInteraction.Interaction.Message.NetworkerId = networkerId; contactInteraction.Interaction.Message.Networker = networker; contactInteraction.Interaction.Contact = db.Contacts.Where(c => c.Id == contactInteraction.Interaction.ContactId).Select(c => c).SingleOrDefault(); contactInteraction.Interaction.Message.NetworkerId = db.Contacts.Where(c => c.Id == contactInteraction.Interaction.ContactId).Select(c => c.NetworkerId).SingleOrDefault(); contactInteraction.Interaction.Message.Networker = networker; contactInteraction.Interaction.Message.Networker.Id = networkerId; contactInteraction.Interaction.Message.Postmark = DateTime.Now; contactInteraction.Interaction.Message.IsInteraction = true; db.Interactions.Add(contactInteraction.Interaction); db.SaveChanges(); var moment = contactInteraction.Interaction.Moment; if (moment >= recent) { contactInteraction.Contact.InContact = true; contactInteraction.Contact.InContactCountDown = moment; networker.RunningTally++; db.Entry(networker).State = EntityState.Modified; db.SaveChanges(); if (networker.Goal != null && networker.RunningTally >= networker.Goal && networker.GoalStatus == true) { networker.GoalCoolDown = DateTime.Now; networker.GoalStatus = false; networker.RunningTally = 0; db.Entry(networker).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Goal", "Interactions", new { code = goalCode })); } return(RedirectToAction("Index", new { id = contactInteraction.Contact.Id })); } } return(View(contactInteraction)); }