public ActionResult MembershipDetails()
        {
            SiteMenuHelper.Instance.CurrentSiteMenu = SiteMenu.Account;
            var userId = MembershipHelper.GetUserIdByEmail(HttpContext.User.Identity.Name);
            var userDetails = db.UserDetails.Single(i => i.UserId == userId);

            var universities = db.Universities
                                    .Select(i => new { Text = i.UniversityName, Value = i.UniversityId }).AsEnumerable()
                                    .Select(x => new SelectListItem { Text = x.Text, Value = x.Value.ToString(), Selected = (userDetails.UniversityId.HasValue ? x.Value == userDetails.UniversityId.Value : false )}).ToList();
            var deliveryLocations = db.University_Delivery
                                    .Where(i => userDetails.UniversityId.HasValue ? i.UniversityId == userDetails.UniversityId : false)
                                    .Select(i => new { i.UniversityDeliveryId, i.Location.BusinessName, i.DeliveryTime }).AsEnumerable()
                                    .Select(i => new SelectListItem { Text = i.BusinessName + " " + i.DeliveryTime.ToString("hh:mm tt"), Value = i.UniversityDeliveryId.ToString(), Selected = userDetails.UniversityDeliveryId.HasValue? userDetails.UniversityDeliveryId.Value == i.UniversityDeliveryId : false }).ToList();

            var detailModel = new UserDetailsViewModel
            {
                FirstName = userDetails.FirstName,
                LastName = userDetails.LastName,
                PhoneNumber = userDetails.PhoneNumber,
                LocationFirstName = userDetails.Location != null ? userDetails.Location.FirstName : "",
                LocationLastName = userDetails.Location != null ? userDetails.Location.LastName : "",
                Address1 = userDetails.Location != null ? userDetails.Location.Address1 : "",
                Address2 = userDetails.Location != null ? userDetails.Location.Address2 : "",
                City = userDetails.Location != null ? userDetails.Location.City : "",
                State = userDetails.Location != null ? userDetails.Location.StateOrProvince : "",
                ZipCode = userDetails.Location != null ? userDetails.Location.ZipCode : "",
                Universities = universities,
                States = MyLunchBox.Models.StatesRepository.Instance.StatesListWithSelectedItem(userDetails.Location != null ? userDetails.Location.StateOrProvince : ""),
                DeliveryLocations = deliveryLocations,
                UniversityId = userDetails.UniversityId.HasValue ? userDetails.UniversityId.Value : -1,
                UniversityDeliveryId = userDetails.UniversityDeliveryId.HasValue ? userDetails.UniversityDeliveryId.Value : -1
            };
            return View( detailModel);
        }
 public ActionResult MembershipDetails(FormCollection values)
 {
     var userId = MembershipHelper.GetUserIdByEmail(HttpContext.User.Identity.Name);
     var userDetails = db.UserDetails.Single(i=>i.UserId == userId);
     userDetails.FirstName = values["firstName"];
     userDetails.LastName = values["lastName"];
     userDetails.PhoneNumber = values["phoneNumber"];
     userDetails.UniversityId = Convert.ToInt32(values["UniversityId"]);
     userDetails.UniversityDeliveryId = Convert.ToInt32(values["UniversityDeliveryId"]);
     if (userDetails.Location == null)
     {
         var location = new Location()
         {
             LocationName = values["LocationFirstName"] + values["LocationLastName"],
             FirstName = values["LocationFirstName"],
             LastName = values["LocationLastName"],
             Address1 = values["Address1"],
             Address2 = values["Address2"],
             City = values["City"],
             StateOrProvince = values["State"],
             ZipCode = values["ZipCode"],
             CountryCode = "US",
             Country = "United States"
         };
         db.Locations.AddObject(location);
         db.SaveChanges();
         userDetails.LocationId = location.LocationId;
     }
     else
     {
         userDetails.Location.FirstName = values["LocationFirstName"];
         userDetails.Location.LastName = values["LocationLastName"];
         userDetails.Location.Address1 = values["Address1"];
         userDetails.Location.Address2 = values["Address2"];
         userDetails.Location.City = values["City"];
         userDetails.Location.StateOrProvince = values["State"];
         userDetails.Location.ZipCode = values["ZipCode"];
     }
     try
     {
         db.UserDetails.ApplyCurrentValues(userDetails);
         db.SaveChanges();
         ViewBag.UpdateStatus = "Successful";
     }
     catch (Exception ex)
     {
         ViewBag.UpdateStatus = ex.Message;
     }
     var universities = db.Universities
                             .Select(i => new { Text = i.UniversityName, Value = i.UniversityId }).AsEnumerable()
                             .Select(x => new SelectListItem { Text = x.Text, Value = x.Value.ToString(), Selected = (userDetails.UniversityId.HasValue ? userDetails.UniversityId.Value == x.Value : false)}).ToList();
     var deliveryLocations = db.University_Delivery
                             .Where(i => userDetails.UniversityId.HasValue ? i.UniversityId == userDetails.UniversityId : false)
                             .Select(i => new { i.UniversityDeliveryId, i.Location.BusinessName, i.DeliveryTime }).AsEnumerable()
                             .Select(i => new SelectListItem { Text = i.BusinessName + " " + i.DeliveryTime.ToString("hh:mm tt"), Value = i.UniversityDeliveryId.ToString(),
                                 Selected = (userDetails.UniversityDeliveryId.HasValue? i.UniversityDeliveryId== userDetails.UniversityDeliveryId.Value : false )}).ToList();
     var detailModel = new UserDetailsViewModel
     {
         FirstName = userDetails.FirstName,
         LastName = userDetails.LastName,
         PhoneNumber = userDetails.PhoneNumber,
         LocationFirstName = userDetails.Location != null ? userDetails.Location.FirstName : "",
         LocationLastName = userDetails.Location != null ? userDetails.Location.LastName : "",
         Address1 = userDetails.Location != null ? userDetails.Location.Address1 : "",
         Address2 = userDetails.Location != null ? userDetails.Location.Address2 : "",
         City = userDetails.Location != null ? userDetails.Location.City : "",
         State = userDetails.Location != null ? userDetails.Location.StateOrProvince : "",
         ZipCode = userDetails.Location != null ? userDetails.Location.ZipCode : "",
         Universities = universities,
         States = MyLunchBox.Models.StatesRepository.Instance.StatesListWithSelectedItem(userDetails.Location != null ? userDetails.Location.StateOrProvince : ""),
         DeliveryLocations = deliveryLocations,
         UniversityId = userDetails.UniversityId.HasValue ? userDetails.UniversityId.Value : -1,
         UniversityDeliveryId = userDetails.UniversityDeliveryId.HasValue ? userDetails.UniversityDeliveryId.Value : -1
     };
     return View(detailModel);
 }