public ActionResult Edit(UserSocialNetwork usersocialnetwork)
 {
     if (ModelState.IsValid)
     {
         context.Entry(usersocialnetwork).State = EntityState.Modified;
         context.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.PossibleSocialNetworks = context.SocialNetworks;
     return View(usersocialnetwork);
 }
        public ActionResult Create(UserSocialNetwork usersocialnetwork)
        {
            if (ModelState.IsValid)
            {
                context.UserSocialNetworks.Add(usersocialnetwork);
                context.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.PossibleSocialNetworks = context.SocialNetworks;
            return View(usersocialnetwork);
        }
        public virtual List<UserSocialNetwork> UserSocialNetwork_GetAllForUser(int UserId)
        {
            UserSocialNetwork item = new UserSocialNetwork();

            if (UserId < 1)
                return (new List<UserSocialNetwork>() { item });

            IEnumerable<UserSocialNetwork> items = _context.UserSocialNetworks.Where(x => x.UserID == UserId);

            return (items.ToList());
        }
        //public virtual ObjectResult<UserProfileSummary_Get_Result> UserProfileSummary_Get(Nullable<int> userID)
        //{
        //    var userIDParameter = userID.HasValue ?
        //        new SqlParameter("UserID", userID) :
        //        new SqlParameter("UserID", typeof(int));
        //    return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<UserProfileSummary_Get_Result>("UserProfileSummary_Get @UserID", userIDParameter);
        //}
        //public virtual UserProfileSummary_Get_Result UserProfileSummary_Get(int userID)
        //{
        //    //using (NuvolaResumeContext context = new NuvolaResumeContext())
        //    {
        //        UserProfile item = UserProfile_GetUserProfile(userID);
        //        UserProfileSummary_Get_Result ret = new UserProfileSummary_Get_Result();
        //        ret.ID = item.ID;
        //        ret.AchievementsCount = item.Achievements.Count();
        //        ret.CompanyCount = item.Companies.Count();
        //        ret.EducationsCount = item.Educations.Count();
        //        ret.SkillsCount = item.Skills.Count();
        //        ret.UserSocialNetworksCount = item.UserSocialNetworks.Count();
        //        ret.VolunteerExperiencesCount = item.VolunteerExperiences.Count();
        //        UserProfilePercentCompleteView upPer = UserProfilePercentCompleteView(userID);
        //        ret.PercentComplete = upPer.PercentComplete;
        //        return (ret);
        //    }
        //}
        //public virtual UserProfilePercentCompleteView UserProfilePercentCompleteView(int userID)
        //{
        //    //SELECT        UserID, Flag, CONVERT(decimal(18, 0), Flag) / 8 AS PercentComplete
        //    //FROM            (
        //    //    SELECT        ID AS UserID,
        //    //CAST(CASE WHEN FirstName IS NULL THEN 0 ELSE 1 END +
        //    //CASE WHEN LastName IS NULL
        //    //    THEN 0 ELSE 1 END + CASE WHEN Street IS NULL THEN 0 ELSE 1 END +
        //    //CASE WHEN City IS NULL
        //    //    THEN 0 ELSE 1 END + CASE WHEN StateProvince IS NULL THEN 0 ELSE 1 END + CASE WHEN CountryID IS NULL
        //    //    THEN 0 ELSE 1 END + CASE WHEN PhoneNumber1 IS NULL THEN 0 ELSE 1 END + CASE WHEN EMailAddress1 IS NULL
        //    //THEN 0 ELSE 1 END AS int)
        //    //    AS Flag
        //    //FROM            dbo.UserProfiles) AS UserComplete
        //    //using (NuvolaResumeContext context = new NuvolaResumeContext())
        //    {
        //        UserProfile item = UserProfile_GetUserProfile(userID);
        //        UserProfilePercentCompleteView ret = new UserProfilePercentCompleteView();
        //        int flag = (
        //            (String.IsNullOrEmpty(item.FirstName) ? 0 : 1) +
        //            (String.IsNullOrEmpty(item.LastName) ? 0 : 1) +
        //            (String.IsNullOrEmpty(item.Street) ? 0 : 1) +
        //            (String.IsNullOrEmpty(item.City) ? 0 : 1) +
        //            (String.IsNullOrEmpty(item.StateProvince) ? 0 : 1) +
        //            (String.IsNullOrEmpty(item.PhoneNumber1) ? 0 : 1) +
        //            (item.CountryID == null ? 0 : 1) +
        //            (String.IsNullOrEmpty(item.EMailAddress1) ? 0 : 1));
        //        ret.UserID = item.ID;
        //        ret.Flag = flag;
        //        ret.PercentComplete = ((decimal)flag / 8) * 100;
        //        return (ret);
        //    }
        //}
        //public virtual ObjectResult<int> UserSearch(string searchWord)
        //{
        //    var searchWordParameter = searchWord != null ?
        //        new SqlParameter("SearchWord", searchWord) :
        //        new SqlParameter("SearchWord", typeof(string));
        //    return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<int>("UserSearch", searchWordParameter);
        //}
        ////public virtual ObjectResult<int> UserSocialNetwork_Save(Nullable<int> iD, Nullable<int> userID, Nullable<int> socialNetworkID, string socialNetworkAccount, string displayAs)
        ////{
        ////    var iDParameter = iD.HasValue ?
        ////        new SqlParameter("ID", iD) :
        ////        new SqlParameter("ID", typeof(int));
        ////    var userIDParameter = userID.HasValue ?
        ////        new SqlParameter("UserID", userID) :
        ////        new SqlParameter("UserID", typeof(int));
        ////    var socialNetworkIDParameter = socialNetworkID.HasValue ?
        ////        new SqlParameter("SocialNetworkID", socialNetworkID) :
        ////        new SqlParameter("SocialNetworkID", typeof(int));
        ////    var socialNetworkAccountParameter = socialNetworkAccount != null ?
        ////        new SqlParameter("SocialNetworkAccount", socialNetworkAccount) :
        ////        new SqlParameter("SocialNetworkAccount", typeof(string));
        ////    var displayAsParameter = displayAs != null ?
        ////        new SqlParameter("DisplayAs", displayAs) :
        ////        new SqlParameter("DisplayAs", typeof(string));
        ////    return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<int>("UserSocialNetwork_Save", iDParameter, userIDParameter, socialNetworkIDParameter, socialNetworkAccountParameter, displayAsParameter);
        ////}
        //public virtual UserSocialNetwork UserSocialNetwork_Save(Nullable<int> iD, Nullable<int> userID, Nullable<int> socialNetworkID, string socialNetworkAccount, string displayAs)
        //{
        //    //using (NuvolaResumeContext context = new NuvolaResumeContext())
        //    {
        //        UserSocialNetwork item = new UserSocialNetwork();
        //        if (iD.HasValue)
        //        {
        //            //Find the item
        //            item = _context.UserSocialNetworks.SingleOrDefault(x => x.ID == iD.Value);
        //        }
        //        else
        //        {
        //            //Create a new item, we don't have an ID
        //            item = new UserSocialNetwork();
        //        }
        //        //Update / Set properties
        //        item.UserID = userID;
        //        item.SocialNetworkID = socialNetworkID;
        //        item.SocialNetworkAccount = socialNetworkAccount;
        //        item.DisplayAs = displayAs;
        //        if (iD.HasValue)
        //        {
        //            //Add the new item to the database
        //            _context.UserSocialNetworks.Add(item);
        //        }
        //        _context.SaveChanges();
        //        return (item);
        //    }
        //}
        //public virtual ObjectResult<int> UserSocialNetworks_DeleteAllByUserId(Nullable<int> userId)
        //{
        //    var userIdParameter = userId.HasValue ?
        //        new SqlParameter("UserId", userId) :
        //        new SqlParameter("UserId", typeof(int));
        //    return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<int>("UserSocialNetworks_DeleteAllByUserId", userIdParameter);
        //}
        ////public virtual ObjectResult<UserSocialNetworks_GetAllForUser_Result> UserSocialNetworks_GetAllForUser(Nullable<int> userID)
        ////{
        ////    var userIDParameter = userID.HasValue ?
        ////        new SqlParameter("UserID", userID) :
        ////        new SqlParameter("UserID", typeof(int));
        ////    return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<UserSocialNetworks_GetAllForUser_Result>("UserSocialNetworks_GetAllForUser", userIDParameter);
        ////}
        //public virtual IEnumerable<UserSocialNetwork> UserSocialNetworks_GetAllForUser(Nullable<int> userID)
        //{
        //    //using (NuvolaResumeContext context = new NuvolaResumeContext())
        //    {
        //        IEnumerable<UserSocialNetwork> items = _context.UserSocialNetworks.Where(x => x.UserID == userID);
        //        return (items.ToList());
        //    }
        //}
        //public virtual ObjectResult<UserSocialNetworks_GetById_Result> UserSocialNetworks_GetById(Nullable<int> iD)
        //{
        //    var iDParameter = iD.HasValue ?
        //        new SqlParameter("ID", iD) :
        //        new SqlParameter("ID", typeof(int));
        //    return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<UserSocialNetworks_GetById_Result>("UserSocialNetworks_GetById", iDParameter);
        //}
        //public virtual ObjectResult<int> VolunteerExperience_Save(Nullable<int> iD, string name, string summary, Nullable<System.DateTime> dateStart, Nullable<System.DateTime> dateEnd, Nullable<int> userID)
        //{
        //    var iDParameter = iD.HasValue ?
        //        new SqlParameter("ID", iD) :
        //        new SqlParameter("ID", typeof(int));
        //    var nameParameter = name != null ?
        //        new SqlParameter("Name", name) :
        //        new SqlParameter("Name", typeof(string));
        //    var summaryParameter = summary != null ?
        //        new SqlParameter("Summary", summary) :
        //        new SqlParameter("Summary", typeof(string));
        //    var dateStartParameter = dateStart.HasValue ?
        //        new SqlParameter("DateStart", dateStart) :
        //        new SqlParameter("DateStart", typeof(System.DateTime));
        //    var dateEndParameter = dateEnd.HasValue ?
        //        new SqlParameter("DateEnd", dateEnd) :
        //        new SqlParameter("DateEnd", typeof(System.DateTime));
        //    var userIDParameter = userID.HasValue ?
        //        new SqlParameter("UserID", userID) :
        //        new SqlParameter("UserID", typeof(int));
        //    return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<int>("VolunteerExperience_Save", iDParameter, nameParameter, summaryParameter, dateStartParameter, dateEndParameter, userIDParameter);
        //}
        public virtual UserSocialNetwork UserSocialNetwork_Get(int Id)
        {
            UserSocialNetwork item = new UserSocialNetwork();

            if (Id < 1)
                return (item);

            //using (NuvolaResumeContext context = new NuvolaResumeContext())
            {
                //_context.Configuration.ProxyCreationEnabled = false;
                item = _context.UserSocialNetworks.Include(x => x.SocialNetwork).SingleOrDefault(x => x.ID == Id);

                if (item == null)
                    return (new UserSocialNetwork());

                return (item);
            }
        }