public ActionResult Edit(int id, Conference conference)
        {
            var existingConference = FindById(id);
            if (existingConference == null) return HttpNotFound();

            if (ModelState.IsValid)
            {
                AddOrReplaceConference(conference);
                return RedirectToAction("Index");
            }

            return View(conference);
        }
        public ActionResult Create(Conference conference)
        {
            if (ModelState.IsValid)
            {
                ClaimsPrincipal principal = ClaimsPrincipal.Current;
                var fullname = string.Format("{0} {1}", principal.FindFirst(ClaimTypes.GivenName).Value,
                                             principal.FindFirst(ClaimTypes.Surname).Value);
                conference.CreatorName = fullname;
                AddOrReplaceConference(conference);
                return RedirectToAction("Index");
            }

            return View(conference);
        }
        private void SendEmailNotificationAboutNewConference(Conference conference)
        {
            var namespaceManager =
                NamespaceManager.CreateFromConnectionString(CloudConfigurationManager.GetSetting("CallForItServiceBus"));

            if (namespaceManager.QueueExists("NewConferenceQueue") == false)
                namespaceManager.CreateQueue("NewConferenceQueue");

            var queueClient =
                QueueClient.CreateFromConnectionString(CloudConfigurationManager.GetSetting("CallForItServiceBus"),
                                                       "NewConferenceQueue");

            var notification = new EmailNotification();

            notification.ToEmailAddress = "*****@*****.**";
            notification.FromEmailAddress = "*****@*****.**";
            notification.Subject = "New Conference!";
            notification.Body = String.Format("Great news! {0} has been scheduled for {1}.", conference.Name,
                                              conference.StartDate);

            queueClient.Send(new BrokeredMessage(notification));
        }
        private void AddOrReplaceConference(Conference conference)
        {
            using (var context = new EFContext())
            {
                if (conference.Id == default(int))
                {
                    // Add Scenario
                    context.Conferences.Add(conference);
                    context.SaveChanges();

                    SendEmailNotificationAboutNewConference(conference);
                }
                else
                {
                    // Update Scenario
                    conference = context.Conferences.Attach(conference);
                    context.Entry(conference).State = System.Data.EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }