public void SaveLibrary(MyLibrary myLibrary)
 {
     if (myLibrary.MyLibraryId == 0)
     {
         context.MyLibraries.Add(myLibrary);
     }
     context.SaveChanges();
 }
        public void DeleteLibrary(MyLibrary myLibrary)
        {
            try
            {
                // Duplicate Check
                var libraries =  from l in context.MyLibraries
                                 where l.ResourceId == myLibrary.ResourceId
                                 where l.UserId == myLibrary.UserId
                                 select l;
                foreach (var l in libraries)
                {
                    context.MyLibraries.Remove(l);
                }

                context.SaveChanges();
            }
            catch
            {
                // Do Nothing
            }
        }
        public ActionResult SaveMyLibrary(int resourceId)
        {
            if (Request.IsAjaxRequest())
            {
                // Identify User
                MembershipUser currentUser = Membership.GetUser();
                Guid userId = new Guid(currentUser.ProviderUserKey.ToString());

                MyLibrary library = new MyLibrary
                {
                    ResourceId = resourceId,
                    UserId = userId
                };
                libraryRepository.SaveLibrary(library);

                return View();
            }
            else
            {
                return View();
            }
        }