public List <MediaCollection> GetMediaCollectionsDescriptions(string UserName, MediaType MediaType)
        {
            int Id = 0;

            XmlDocument XMLStore = new XmlDocument();

            XMLStore.Load(XMLDescriptionFile);
            XmlElement root = XMLStore.DocumentElement;

            List <MediaCollection> mediaCollections = new List <MediaCollection>();

            foreach (XmlNode item in root.ChildNodes)
            {
                if (item.Attributes["UserName"].Value.ToString() == UserName &&
                    item.Attributes["MediaType"].Value.ToString() == ((int)MediaType).ToString())
                {
                    MediaCollection mediaCollection = new MediaCollection();
                    mediaCollection.Id          = Id;
                    mediaCollection.UserName    = item.Attributes["UserName"].Value.ToString();
                    mediaCollection.MediaType   = MediaType;
                    mediaCollection.ShortTitle  = item.Attributes["ShortTitle"].Value.ToString();
                    mediaCollection.Title       = item.Attributes["Title"].Value.ToString();
                    mediaCollection.Location    = item.Attributes["Location"].Value.ToString();
                    mediaCollection.Description = item.Attributes["Description"].Value.ToString();

                    mediaCollections.Add(mediaCollection);
                }
                ++Id;
            }

            return(mediaCollections);
        }
        public void AddMediaCollectionDescription(MediaCollection MediaCollection)
        {
            XmlDocument XMLStore = new XmlDocument();
            XMLStore.Load(XMLDescriptionFile);

            XmlElement node_mediaCollection = XMLStore.CreateElement("item" + (GetLastCollectionId() + 2));

            XmlAttribute attr_userName = XMLStore.CreateAttribute("UserName");
            attr_userName.Value = MediaCollection.UserName;
            node_mediaCollection.Attributes.Append(attr_userName);

            XmlAttribute attr_mediaType = XMLStore.CreateAttribute("MediaType");
            attr_mediaType.Value = MediaCollection.MediaType.ToString();
            node_mediaCollection.Attributes.Append(attr_mediaType);

            XmlAttribute attr_Location = XMLStore.CreateAttribute("Location");
            attr_Location.Value = MediaCollection.Location;
            node_mediaCollection.Attributes.Append(attr_Location);

            XmlAttribute attr_ShortTitle = XMLStore.CreateAttribute("ShortTitle");
            attr_ShortTitle.Value = MediaCollection.ShortTitle;
            node_mediaCollection.Attributes.Append(attr_ShortTitle);

            XmlAttribute attr_Title = XMLStore.CreateAttribute("Title");
            attr_Title.Value = MediaCollection.ShortTitle;
            node_mediaCollection.Attributes.Append(attr_Title);

            XmlAttribute attr_Description = XMLStore.CreateAttribute("Description");
            attr_Description.Value = MediaCollection.Description;
            node_mediaCollection.Attributes.Append(attr_Description);

            XMLStore.DocumentElement.InsertAfter(node_mediaCollection, XMLStore.DocumentElement.LastChild);

            XMLStore.Save(XMLDescriptionFile);
        }
        //SHOW ITEM
        public ActionResult ShowItem(int CollectionId)
        {
            MediaCollection MediaCollection = new MediaCollection();
            MediaCollection = repository.GetMediaCollectionDescription(CollectionId);
            ViewBag.collectionTitle = MediaCollection.ShortTitle.ToString();

            return View(repository.TransformToVideoMediaCollection(CollectionId));
        }
        public List <MediaCollection> GetMediaCollectionsDescriptions(string UserName, MediaType MediaType)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionString);
            NpgsqlCommand    command    = new NpgsqlCommand(@"SELECT * FROM dbo.""MediaCollections"" WHERE UserName = :UserName AND MediaType = :MediaType", connection);

            command.Parameters.Add(new NpgsqlParameter("UserName", NpgsqlDbType.Varchar));
            command.Parameters[0].Value = UserName;

            command.Parameters.Add(new NpgsqlParameter("MediaType", NpgsqlDbType.Integer));
            command.Parameters[1].Value = (int)MediaType;

            NpgsqlCommand command2 = new NpgsqlCommand(@"SELECT * FROM dbo.""MediaElements"" WHERE CollectionId = :CollectionId", connection);

            connection.Open();
            NpgsqlDataReader reader = command.ExecuteReader();

            List <MediaCollection> mediacollections = new List <MediaCollection>();

            while (reader.Read())
            {
                MediaCollection mediacollection = new MediaCollection();
                mediacollection.Id          = (int)reader[0];
                mediacollection.UserName    = (string)reader[1];
                mediacollection.ShortTitle  = (string)reader[2];
                mediacollection.Title       = (string)reader[3];
                mediacollection.Description = (string)reader[4];
                mediacollection.Location    = (string)reader[5];
                mediacollection.MediaType   = MediaType;

                mediacollections.Add(mediacollection);
            }
            reader.Dispose();

            List <MediaElement> mediaelements = new List <MediaElement>();

            foreach (MediaCollection mediacollection in mediacollections)
            {
                command2.Parameters.Add(new NpgsqlParameter("CollectionId", NpgsqlDbType.Integer));
                command2.Parameters[0].Value = mediacollection.Id;
                NpgsqlDataReader reader2 = command2.ExecuteReader();

                while (reader2.Read())
                {
                    MediaElement mediaelement = new MediaElement();
                    mediaelement.Id           = (int)reader2[0];
                    mediaelement.CollectionId = (int)reader2[1];
                    mediaelement.File         = (string)reader2[2];

                    mediaelements.Add(mediaelement);
                }
                reader2.Dispose();

                mediacollection.MediaElements = mediaelements;
            }
            connection.Close();

            return(mediacollections);
        }
        //SHOW ITEM
        public ActionResult ShowItem(int CollectionId)
        {
            MediaCollection MediaCollection = new MediaCollection();
            MediaCollection = repository.GetMediaCollectionDescription(CollectionId);
            ViewBag.collectionTitle = MediaCollection.ShortTitle.ToString();
            ViewBag.collectionFolder = MediaCollection.Location.ToString();

            return View(MediaCollection.MediaElements.ToList());
        }
        public void EraseMediaCollection(int CollectionId)
        {
            List <MediaElement> Medias = medias.FindAll(x => x.CollectionId == CollectionId).ToList();

            foreach (var Media in Medias)
            {
                medias.Remove(Media);
            }
            MediaCollection MediaCollection = mediacollections.Find(x => x.Id == CollectionId);

            mediacollections.Remove(MediaCollection);
        }
        public MediaCollection GetMediaCollectionDescription(int CollectionId)
        {
            XmlDocument XMLStore = new XmlDocument();

            XMLStore.Load(XMLDescriptionFile);
            XmlNodeList root           = XMLStore.DocumentElement.ChildNodes;
            XmlNode     collectionNode = root[CollectionId];

            MediaCollection mediaCollection = new MediaCollection();

            mediaCollection.Id       = CollectionId;
            mediaCollection.UserName = collectionNode.Attributes["UserName"].Value.ToString();

            switch (collectionNode.Attributes["MediaType"].Value.ToString())
            {
            case "Photo":
                mediaCollection.MediaType = MediaType.Photo;
                break;

            case "Graphics":
                mediaCollection.MediaType = MediaType.Graphic;
                break;

            case "Video":
                mediaCollection.MediaType = MediaType.Video;
                break;
            }

            mediaCollection.ShortTitle = collectionNode.Attributes["ShortTitle"].Value.ToString();
            mediaCollection.Title      = collectionNode.Attributes["Title"].Value.ToString();
            mediaCollection.Location   = collectionNode.Attributes["Location"].Value.ToString();

            int Id = 1;
            List <MediaElement> mediaElements = new List <MediaElement>();

            foreach (XmlNode elementNode in collectionNode)
            {
                MediaElement mediaElement = new MediaElement();
                mediaElement.CollectionId = CollectionId;
                mediaElement.Id           = Id++;
                mediaElement.File         = elementNode.Attributes["fileName"].Value.ToString();

                mediaElements.Add(mediaElement);
            }

            mediaCollection.MediaElements = mediaElements;

            return(mediaCollection);
        }
        public void AddMediaCollectionDescription(MediaCollection MediaCollection)
        {
            XmlDocument XMLStore = new XmlDocument();

            XMLStore.Load(XMLDescriptionFile);

            XmlElement node_mediaCollection = XMLStore.CreateElement("item" + (GetLastCollectionId() + 2));

            XmlAttribute attr_userName = XMLStore.CreateAttribute("UserName");

            attr_userName.Value = MediaCollection.UserName;
            node_mediaCollection.Attributes.Append(attr_userName);

            XmlAttribute attr_mediaType = XMLStore.CreateAttribute("MediaType");

            attr_mediaType.Value = MediaCollection.MediaType.ToString();
            node_mediaCollection.Attributes.Append(attr_mediaType);

            XmlAttribute attr_Location = XMLStore.CreateAttribute("Location");

            attr_Location.Value = MediaCollection.Location;
            node_mediaCollection.Attributes.Append(attr_Location);

            XmlAttribute attr_ShortTitle = XMLStore.CreateAttribute("ShortTitle");

            attr_ShortTitle.Value = MediaCollection.ShortTitle;
            node_mediaCollection.Attributes.Append(attr_ShortTitle);

            XmlAttribute attr_Title = XMLStore.CreateAttribute("Title");

            attr_Title.Value = MediaCollection.ShortTitle;
            node_mediaCollection.Attributes.Append(attr_Title);

            XmlAttribute attr_Description = XMLStore.CreateAttribute("Description");

            attr_Description.Value = MediaCollection.Description;
            node_mediaCollection.Attributes.Append(attr_Description);


            XMLStore.DocumentElement.InsertAfter(node_mediaCollection, XMLStore.DocumentElement.LastChild);

            XMLStore.Save(XMLDescriptionFile);
        }
        public void EraseMediaCollection(int CollectionId)
        {
            List <MediaElement> Medias = db.MediaElements.Where(x => x.CollectionId == CollectionId).ToList();

            foreach (var Media in Medias)
            {
                string mediafile = AppDomain.CurrentDomain.BaseDirectory + "/Content/MembersFiles/" + Media.File;
                if (File.Exists(mediafile))
                {
                    File.Delete(mediafile);
                }
                db.MediaElements.Remove(Media);
            }

            MediaCollection MediaCollection = db.MediaCollections.First(x => x.Id == CollectionId);

            db.MediaCollections.Remove(MediaCollection);
            db.SaveChanges();
        }
        public List <MediaCollection> GetAllMediaCollectionsDescriptions()
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionString);
            NpgsqlCommand    command    = new NpgsqlCommand(@"SELECT * FROM dbo.""MediaCollections""", connection);

            connection.Open();
            NpgsqlDataReader reader = command.ExecuteReader();

            List <MediaCollection> mediacollections = new List <MediaCollection>();

            while (reader.Read())
            {
                MediaCollection mediacollection = new MediaCollection();
                mediacollection.Id          = (int)reader[0];
                mediacollection.UserName    = (string)reader[1];
                mediacollection.ShortTitle  = (string)reader[2];
                mediacollection.Title       = (string)reader[3];
                mediacollection.Description = (string)reader[4];
                mediacollection.Location    = (string)reader[5];

                Int16 mediatype = (Int16)reader[6];
                switch (mediatype)
                {
                case 0:
                    mediacollection.MediaType = MediaType.Photo;
                    break;

                case 1:
                    mediacollection.MediaType = MediaType.Graphic;
                    break;

                case 2:
                    mediacollection.MediaType = MediaType.Video;
                    break;
                }

                mediacollections.Add(mediacollection);
            }
            reader.Dispose();
            connection.Close();

            return(mediacollections);
        }
        public List <MediaCollection> GetAllMediaCollectionsDescriptions()
        {
            int Id = 0;

            XmlDocument XMLStore = new XmlDocument();

            XMLStore.Load(XMLDescriptionFile);

            List <MediaCollection> mediaCollections = new List <MediaCollection>();

            foreach (XmlNode item in XMLStore.DocumentElement.ChildNodes)
            {
                MediaCollection mediaCollection = new MediaCollection();
                mediaCollection.Id       = Id;
                mediaCollection.UserName = item.Attributes["UserName"].Value.ToString();

                switch (item.Attributes["mediaType"].Value.ToString())
                {
                case "Photo":
                    mediaCollection.MediaType = MediaType.Photo;
                    break;

                case "Graphics":
                    mediaCollection.MediaType = MediaType.Graphic;
                    break;

                case "Video":
                    mediaCollection.MediaType = MediaType.Video;
                    break;
                }

                mediaCollection.ShortTitle = item.Attributes["ShortTitle"].Value.ToString();
                mediaCollection.Title      = item.Attributes["Title"].Value.ToString();
                mediaCollection.Location   = item.Attributes["Location"].Value.ToString();

                mediaCollections.Add(mediaCollection);

                ++Id;
            }

            return(mediaCollections);
        }
        public void AddMediaCollectionDescription(MediaCollection MediaCollection)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionString);
            NpgsqlCommand command = new NpgsqlCommand(@"INSERT INTO dbo.""MediaCollections"" (UserName, ShortTitle, Title, Description, Location, MediaType) VALUES (:UserName, :ShortTitle, :Title, :Description, :Location, :MediaType)", connection);
            command.Parameters.Add(new NpgsqlParameter("UserName", NpgsqlDbType.Varchar));
            command.Parameters[0].Value = MediaCollection.UserName;
            command.Parameters.Add(new NpgsqlParameter("ShortTitle", NpgsqlDbType.Varchar));
            command.Parameters[1].Value = MediaCollection.ShortTitle;
            command.Parameters.Add(new NpgsqlParameter("Title", NpgsqlDbType.Varchar));
            command.Parameters[2].Value = MediaCollection.Title;
            command.Parameters.Add(new NpgsqlParameter("Description", NpgsqlDbType.Varchar));
            command.Parameters[3].Value = MediaCollection.Description;
            command.Parameters.Add(new NpgsqlParameter("Location", NpgsqlDbType.Varchar));
            command.Parameters[4].Value = MediaCollection.Location;
            command.Parameters.Add(new NpgsqlParameter("MediaType", NpgsqlDbType.Smallint));
            command.Parameters[5].Value = (Int16)MediaCollection.MediaType;

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
        public void AddMediaCollectionDescription(MediaCollection MediaCollection)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionString);
            NpgsqlCommand    command    = new NpgsqlCommand(@"INSERT INTO dbo.""MediaCollections"" (UserName, ShortTitle, Title, Description, Location, MediaType) VALUES (:UserName, :ShortTitle, :Title, :Description, :Location, :MediaType)", connection);

            command.Parameters.Add(new NpgsqlParameter("UserName", NpgsqlDbType.Varchar));
            command.Parameters[0].Value = MediaCollection.UserName;
            command.Parameters.Add(new NpgsqlParameter("ShortTitle", NpgsqlDbType.Varchar));
            command.Parameters[1].Value = MediaCollection.ShortTitle;
            command.Parameters.Add(new NpgsqlParameter("Title", NpgsqlDbType.Varchar));
            command.Parameters[2].Value = MediaCollection.Title;
            command.Parameters.Add(new NpgsqlParameter("Description", NpgsqlDbType.Varchar));
            command.Parameters[3].Value = MediaCollection.Description;
            command.Parameters.Add(new NpgsqlParameter("Location", NpgsqlDbType.Varchar));
            command.Parameters[4].Value = MediaCollection.Location;
            command.Parameters.Add(new NpgsqlParameter("MediaType", NpgsqlDbType.Smallint));
            command.Parameters[5].Value = (Int16)MediaCollection.MediaType;

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
        public List<MediaCollection> GetMediaCollectionsDescriptions(string UserName, MediaType MediaType)
        {
            int Id=0;

            XmlDocument XMLStore = new XmlDocument();
            XMLStore.Load(XMLDescriptionFile);
            XmlElement root = XMLStore.DocumentElement;

            List<MediaCollection> mediaCollections = new List<MediaCollection>();
            foreach (XmlNode item in root.ChildNodes)
            {
                if (item.Attributes["UserName"].Value.ToString() == UserName &&
                    item.Attributes["MediaType"].Value.ToString() == ((int)MediaType).ToString())
                {

                    MediaCollection mediaCollection = new MediaCollection();
                    mediaCollection.Id              = Id;
                    mediaCollection.UserName        = item.Attributes["UserName"].Value.ToString();
                    mediaCollection.MediaType       = MediaType;
                    mediaCollection.ShortTitle      = item.Attributes["ShortTitle"].Value.ToString();
                    mediaCollection.Title           = item.Attributes["Title"].Value.ToString();
                    mediaCollection.Location        = item.Attributes["Location"].Value.ToString();
                    mediaCollection.Description     = item.Attributes["Description"].Value.ToString();

                    mediaCollections.Add(mediaCollection);
                }
                ++Id;
            }

            return mediaCollections;
        }
 public void AddMediaCollectionDescription(MediaCollection MediaCollection)
 {
     db.MediaCollections.Add(MediaCollection);
     db.SaveChanges();
 }
        public List<MediaCollection> GetMediaCollectionsDescriptions(string UserName, MediaType MediaType)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionString);
            NpgsqlCommand command = new NpgsqlCommand(@"SELECT * FROM dbo.""MediaCollections"" WHERE UserName = :UserName AND MediaType = :MediaType", connection);

            command.Parameters.Add(new NpgsqlParameter ("UserName", NpgsqlDbType.Varchar));
            command.Parameters[0].Value = UserName;

            command.Parameters.Add(new NpgsqlParameter("MediaType", NpgsqlDbType.Integer));
            command.Parameters[1].Value = (int)MediaType;

            NpgsqlCommand command2 = new NpgsqlCommand(@"SELECT * FROM dbo.""MediaElements"" WHERE CollectionId = :CollectionId", connection);

            connection.Open();
            NpgsqlDataReader reader = command.ExecuteReader();

            List<MediaCollection> mediacollections = new List<MediaCollection>();

            while (reader.Read())
            {
                MediaCollection mediacollection = new MediaCollection();
                mediacollection.Id = (int)reader[0];
                mediacollection.UserName = (string)reader[1];
                mediacollection.ShortTitle =(string)reader[2];
                mediacollection.Title = (string)reader[3];
                mediacollection.Description = (string)reader[4];
                mediacollection.Location = (string)reader[5];
                mediacollection.MediaType = MediaType;

                mediacollections.Add(mediacollection);
            }
            reader.Dispose();

            List<MediaElement> mediaelements = new List<MediaElement>();

            foreach (MediaCollection mediacollection in mediacollections)
            {
                command2.Parameters.Add(new NpgsqlParameter("CollectionId", NpgsqlDbType.Integer));
                command2.Parameters[0].Value = mediacollection.Id;
                NpgsqlDataReader reader2 = command2.ExecuteReader();

                while (reader2.Read())
                {
                    MediaElement mediaelement = new MediaElement();
                    mediaelement.Id = (int)reader2[0];
                    mediaelement.CollectionId = (int)reader2[1];
                    mediaelement.File = (string)reader2[2];

                    mediaelements.Add(mediaelement);
                }
                reader2.Dispose();

                mediacollection.MediaElements = mediaelements;

            }
            connection.Close();

            return mediacollections;
        }
 public void AddMediaCollectionDescription(MediaCollection MediaCollection)
 {
     mediacollections.Add(MediaCollection);
 }
        public MediaCollection GetMediaCollectionDescription(int CollectionId)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionString);
            NpgsqlCommand    command    = new NpgsqlCommand(@"SELECT * FROM dbo.""MediaCollections"" WHERE Id = :CollectionId", connection);

            command.Parameters.Add(new NpgsqlParameter("CollectionId", NpgsqlDbType.Integer));
            command.Parameters[0].Value = CollectionId;

            NpgsqlCommand command2 = new NpgsqlCommand(@"SELECT * FROM dbo.""MediaElements"" WHERE CollectionId = :CollectionId", connection);

            connection.Open();
            NpgsqlDataReader reader = command.ExecuteReader();

            MediaCollection mediacollection = new MediaCollection();

            reader.Read();

            mediacollection.Id          = (int)reader[0];
            mediacollection.UserName    = (string)reader[1];
            mediacollection.ShortTitle  = (string)reader[2];
            mediacollection.Title       = (string)reader[3];
            mediacollection.Description = (string)reader[4];
            mediacollection.Location    = (string)reader[5];

            Int16 mediatype = (Int16)reader[6];

            switch (mediatype)
            {
            case 0:
                mediacollection.MediaType = MediaType.Photo;
                break;

            case 1:
                mediacollection.MediaType = MediaType.Graphic;
                break;

            case 2:
                mediacollection.MediaType = MediaType.Video;
                break;
            }
            reader.Dispose();

            List <MediaElement> mediaelements = new List <MediaElement>();

            command2.Parameters.Add(new NpgsqlParameter("CollectionId", NpgsqlDbType.Integer));
            command2.Parameters[0].Value = mediacollection.Id;
            NpgsqlDataReader reader2 = command2.ExecuteReader();

            while (reader2.Read())
            {
                MediaElement mediaelement = new MediaElement();
                mediaelement.Id           = (int)reader2[0];
                mediaelement.CollectionId = (int)reader2[1];
                mediaelement.File         = (string)reader2[2];

                mediaelements.Add(mediaelement);
            }
            reader2.Dispose();

            mediacollection.MediaElements = mediaelements;

            connection.Close();

            return(mediacollection);
        }
        public List<MediaCollection> GetAllMediaCollectionsDescriptions()
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionString);
            NpgsqlCommand command = new NpgsqlCommand(@"SELECT * FROM dbo.""MediaCollections""", connection);

            connection.Open();
            NpgsqlDataReader reader = command.ExecuteReader();

            List<MediaCollection> mediacollections = new List<MediaCollection>();

            while (reader.Read())
            {
                MediaCollection mediacollection = new MediaCollection();
                mediacollection.Id = (int)reader[0];
                mediacollection.UserName = (string)reader[1];
                mediacollection.ShortTitle = (string)reader[2];
                mediacollection.Title = (string)reader[3];
                mediacollection.Description = (string)reader[4];
                mediacollection.Location = (string)reader[5];

                Int16 mediatype = (Int16)reader[6];
                switch (mediatype)
                {
                    case 0:
                        mediacollection.MediaType = MediaType.Photo;
                        break;
                    case 1:
                        mediacollection.MediaType = MediaType.Graphic;
                        break;
                    case 2:
                        mediacollection.MediaType = MediaType.Video;
                        break;
                }

                mediacollections.Add(mediacollection);
            }
            reader.Dispose();
            connection.Close();

            return mediacollections;
        }
        //[AcceptVerbs(HttpVerbs.Get)]
        //public ActionResult CreateUser()
        //{
        //    return PartialView("UsersCRUD_partial_createUser");
        //}
        //[AcceptVerbs(HttpVerbs.Post)]
        //public ActionResult CreateUser(RegisterModel user)
        //{
        //    if (ModelState.IsValid)
        //    {
        //        MembershipCreateStatus status;
        //        Membership.CreateUser(username: user.UserName, password: user.Password, email: user.Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, status: out status);
        //        if (status == MembershipCreateStatus.Success)
        //        {
        //            return PartialView("UsersCRUD_partial_table", Membership.GetAllUsers());
        //        }
        //        else
        //        {
        //            switch (status)
        //            {
        //                case MembershipCreateStatus.DuplicateUserName:
        //                    ModelState.AddModelError("UserName", "Пользователь с таким именем уже существует");
        //                    break;
        //                default:
        //                    ModelState.AddModelError("", "Неизвестная ошибка");
        //                    break;
        //            }
        //            return PartialView("UsersCRUD_partial_createUser", user);
        //        }
        //    }
        //    else
        //    {
        //        return PartialView("UsersCRUD_partial_createUser", user);
        //    }
        //}
        //[AcceptVerbs(HttpVerbs.Get)]
        //public ActionResult DeleteUser(string username)
        //{
        //    Membership.DeleteUser(username, false);
        //    return PartialView("UsersCRUD_partial_table", Membership.GetAllUsers());
        //}
        //[AcceptVerbs(HttpVerbs.Get)]
        //public ActionResult UpdateUser(string username)
        //{
        //    UpdateModel updateuser = new UpdateModel();
        //    MembershipUser membershipuser = Membership.GetUser(username, false);
        //    updateuser.UserId = (Guid)membershipuser.ProviderUserKey;
        //    updateuser.UserName = membershipuser.UserName;
        //    updateuser.Email = membershipuser.Email;
        //    return PartialView("UsersCRUD_partial_updateUser", updateuser);
        //}
        //[AcceptVerbs(HttpVerbs.Post)]
        //public ActionResult UpdateUser(UpdateModel updateUser)
        //{
        //    return PartialView("UsersCRUD_partial_table", Membership.GetAllUsers());
        //}
        //public ActionResult MakeAdminAccount()
        //{
        //    List<User> users = new List<User>();
        //    using (DBMembershipContext db = new DBMembershipContext())
        //    {
        //        //User newAdminUser = new User();
        //        //newAdminUser = users.First(x => x.UserName == "admin");
        //        //newAdminUser.Password = Encoding.UTF8.GetBytes("admin");
        //        List <User> adminUsers = db.Users.Where(x=>x.UserName=="admin").ToList();
        //        db.Users.RemoveRange(adminUsers);
        //        db.SaveChanges();
        //        List<User> otherUsers = db.Users.Where(x => x.UserName == "other1" || x.UserName == "other2").ToList();
        //        db.Users.RemoveRange(otherUsers);
        //        db.SaveChanges();
        //        User admin = new User();
        //        admin = new User { UserId = Guid.NewGuid(), UserName = "******", Email = "someemail", Password = Encoding.UTF8.GetBytes("admin"), PasswordSalt = 1234, CreatedDate = DateTime.Now, IsActivated = true, IsLockedOut = false, LastLockedOutDate = DateTime.Now, LastLoginDate = DateTime.Now };
        //        db.Users.Add(admin);
        //        db.SaveChanges();
        //        Guid adminGuid = db.Users.FirstOrDefault(x => x.UserName == "admin").UserId;
        //        UserRole adminRole1 = new UserRole();
        //        adminRole1.UserId = adminGuid;
        //        adminRole1.RoleId = db.Roles.FirstOrDefault(x => x.RoleName == "Administrator").RoleId;
        //        db.UserRoles.Add(adminRole1);
        //        db.SaveChanges();
        //        UserRole adminRole2 = new UserRole();
        //        adminRole2.UserId = adminGuid;
        //        adminRole2.RoleId = db.Roles.FirstOrDefault(x => x.RoleName == "Member").RoleId;
        //        db.UserRoles.Add(adminRole2);
        //        db.SaveChanges();
        //        User other1 = new User();
        //        other1 = new User { UserId = Guid.NewGuid(), UserName = "******", Email = "someemail", Password = Encoding.UTF8.GetBytes("other1"), PasswordSalt = 1234, CreatedDate = DateTime.Now, IsActivated = true, IsLockedOut = false, LastLockedOutDate = DateTime.Now, LastLoginDate = DateTime.Now };
        //        db.Users.Add(other1);
        //        db.SaveChanges();
        //        Guid other1Guid = db.Users.FirstOrDefault(x => x.UserName == "other1").UserId;
        //        UserRole other1Role = new UserRole();
        //        other1Role.UserId = other1Guid;
        //        other1Role.RoleId = db.Roles.FirstOrDefault(x => x.RoleName == "Member").RoleId;
        //        db.UserRoles.Add(other1Role);
        //        db.SaveChanges();
        //        User other2 = new User();
        //        other2 = new User { UserId = Guid.NewGuid(), UserName = "******", Email = "someemail", Password = Encoding.UTF8.GetBytes("other2"), PasswordSalt = 1234, CreatedDate = DateTime.Now, IsActivated = true, IsLockedOut = false, LastLockedOutDate = DateTime.Now, LastLoginDate = DateTime.Now };
        //        db.Users.Add(other2);
        //        db.SaveChanges();
        //        Guid other2Guid = db.Users.FirstOrDefault(x => x.UserName == "other2").UserId;
        //        UserRole other2Role = new UserRole();
        //        other2Role.UserId = other2Guid;
        //        other2Role.RoleId = db.Roles.FirstOrDefault(x => x.RoleName == "Member").RoleId;
        //        db.UserRoles.Add(other2Role);
        //        db.SaveChanges();
        //        //db.Users.Add(newAdminUser);
        //        //db.SaveChanges();
        //    }
        //    return RedirectToAction("UsersCRUD");
        //}
        public ActionResult DataFromXMLFiles()
        {
            XmlDocument PhotoXmlFile = new XmlDocument();
                    PhotoXmlFile.Load(AppDomain.CurrentDomain.BaseDirectory + "/Content/PhotoGalleryDescription.xml");

                    foreach (XmlNode collection in PhotoXmlFile.DocumentElement.ChildNodes)
                    {

                        MediaCollection MediaCollection = new MediaCollection();
                        MediaCollection.UserName = "******";
                        MediaCollection.ShortTitle = collection.Attributes["itemTitle"].Value.ToString();
                        MediaCollection.Title = "No title";
                        MediaCollection.Description = "No description";
                        MediaCollection.Location = "mobile/photo/" + collection.Attributes["itemFolder"].Value.ToString();
                        MediaCollection.MediaType = MediaType.Photo;
                        repository.AddMediaCollectionDescription(MediaCollection);

                        foreach (XmlNode collectionitem in collection.ChildNodes)
                        {
                            MediaElement Media = new MediaElement();
                            Media.CollectionId = repository.GetLastCollectionId();
                            Media.File = collectionitem.Attributes["fileName"].Value.ToString();
                            repository.AddMedia(Media);
                        }

                    }

                    XmlDocument GraphicsXmlFile = new XmlDocument();
                    GraphicsXmlFile.Load(AppDomain.CurrentDomain.BaseDirectory + "/Content/GraphicsGalleryDescription.xml");

                    foreach (XmlNode collection in GraphicsXmlFile.DocumentElement.ChildNodes)
                    {

                        MediaCollection MediaCollection = new MediaCollection();
                        MediaCollection.UserName = "******";
                        MediaCollection.ShortTitle = collection.Attributes["itemTitle"].Value.ToString();
                        MediaCollection.Title = "No title";
                        MediaCollection.Description = "No description";
                        MediaCollection.Location = "mobile/graphics/" + collection.Attributes["itemFolder"].Value.ToString();
                        MediaCollection.MediaType = MediaType.Graphic;
                        repository.AddMediaCollectionDescription(MediaCollection);

                        foreach (XmlNode collectionitem in collection.ChildNodes)
                        {
                            MediaElement Media = new MediaElement();
                            Media.CollectionId = repository.GetLastCollectionId();
                            Media.File = collectionitem.Attributes["fileName"].Value.ToString();
                            repository.AddMedia(Media);
                        }

                    }

                    XmlDocument VideoXmlFile = new XmlDocument();
                    VideoXmlFile.Load(AppDomain.CurrentDomain.BaseDirectory + "/Content/VideoGalleryDescription.xml");

                    foreach (XmlNode collection in VideoXmlFile.DocumentElement.ChildNodes)
                    {

                        MediaCollection MediaCollection = new MediaCollection();
                        MediaCollection.UserName = "******";
                        MediaCollection.ShortTitle = collection.Attributes["itemTitle"].Value.ToString();
                        MediaCollection.Title = "No title";
                        MediaCollection.Description = "No description";
                        MediaCollection.Location = "mobile/video/" + collection.Attributes["itemFolder"].Value.ToString();
                        MediaCollection.MediaType = MediaType.Video;
                        repository.AddMediaCollectionDescription(MediaCollection);

                        foreach (XmlNode collectionitem in collection.ChildNodes)
                        {
                            MediaElement Media = new MediaElement();
                            Media.CollectionId = repository.GetLastCollectionId();
                            Media.File = collectionitem.Attributes["fileName"].Value.ToString();
                            repository.AddMedia(Media);
                        }

                    }

            return RedirectToAction("Index");
        }
        public List<MediaCollection> GetAllMediaCollectionsDescriptions()
        {
            int Id = 0;

            XmlDocument XMLStore = new XmlDocument();
            XMLStore.Load(XMLDescriptionFile);

            List<MediaCollection> mediaCollections = new List<MediaCollection>();

            foreach (XmlNode item in XMLStore.DocumentElement.ChildNodes)
            {

                MediaCollection mediaCollection = new MediaCollection();
                mediaCollection.Id              = Id;
                mediaCollection.UserName        = item.Attributes["UserName"].Value.ToString();

                switch (item.Attributes["mediaType"].Value.ToString())
                    {
                        case "Photo":
                            mediaCollection.MediaType = MediaType.Photo;
                            break;
                        case "Graphics":
                            mediaCollection.MediaType = MediaType.Graphic;
                            break;
                        case "Video":
                            mediaCollection.MediaType = MediaType.Video;
                            break;
                    }

                mediaCollection.ShortTitle      = item.Attributes["ShortTitle"].Value.ToString();
                mediaCollection.Title           = item.Attributes["Title"].Value.ToString();
                mediaCollection.Location        = item.Attributes["Location"].Value.ToString();

                mediaCollections.Add(mediaCollection);

                ++Id;
            }

            return mediaCollections;
        }
 public void AddMediaCollectionDescription(MediaCollection MediaCollection)
 {
     mediacollections.Add(MediaCollection);
 }
        public MediaCollection GetMediaCollectionDescription(int CollectionId)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionString);
            NpgsqlCommand command = new NpgsqlCommand(@"SELECT * FROM dbo.""MediaCollections"" WHERE Id = :CollectionId", connection);

            command.Parameters.Add(new NpgsqlParameter("CollectionId", NpgsqlDbType.Integer));
            command.Parameters[0].Value = CollectionId;

            NpgsqlCommand command2 = new NpgsqlCommand(@"SELECT * FROM dbo.""MediaElements"" WHERE CollectionId = :CollectionId", connection);

            connection.Open();
            NpgsqlDataReader reader = command.ExecuteReader();

            MediaCollection mediacollection = new MediaCollection();

            reader.Read();

            mediacollection.Id = (int)reader[0];
            mediacollection.UserName = (string)reader[1];
            mediacollection.ShortTitle = (string)reader[2];
            mediacollection.Title = (string)reader[3];
            mediacollection.Description = (string)reader[4];
            mediacollection.Location = (string)reader[5];

            Int16 mediatype = (Int16)reader[6];
            switch (mediatype)
            {
                case 0:
                    mediacollection.MediaType = MediaType.Photo;
                    break;
                case 1:
                    mediacollection.MediaType = MediaType.Graphic;
                    break;
                case 2:
                    mediacollection.MediaType = MediaType.Video;
                    break;
            }
            reader.Dispose();

            List<MediaElement> mediaelements = new List<MediaElement>();

            command2.Parameters.Add(new NpgsqlParameter("CollectionId", NpgsqlDbType.Integer));
            command2.Parameters[0].Value = mediacollection.Id;
            NpgsqlDataReader reader2 = command2.ExecuteReader();

            while (reader2.Read())
            {
                    MediaElement mediaelement = new MediaElement();
                    mediaelement.Id = (int)reader2[0];
                    mediaelement.CollectionId = (int)reader2[1];
                    mediaelement.File = (string)reader2[2];

                    mediaelements.Add(mediaelement);
            }
            reader2.Dispose();

            mediacollection.MediaElements = mediaelements;

            connection.Close();

            return mediacollection;
        }
        public MediaCollection GetMediaCollectionDescription(int CollectionId)
        {
            XmlDocument XMLStore = new XmlDocument();
            XMLStore.Load(XMLDescriptionFile);
            XmlNodeList root = XMLStore.DocumentElement.ChildNodes;
            XmlNode collectionNode = root[CollectionId];

            MediaCollection mediaCollection     = new MediaCollection();
                mediaCollection.Id              = CollectionId;
                mediaCollection.UserName        = collectionNode.Attributes["UserName"].Value.ToString();

            switch (collectionNode.Attributes["MediaType"].Value.ToString())
                {
                    case "Photo":
                        mediaCollection.MediaType = MediaType.Photo;
                        break;
                    case "Graphics":
                        mediaCollection.MediaType = MediaType.Graphic;
                        break;
                    case "Video":
                        mediaCollection.MediaType = MediaType.Video;
                        break;

                }

                mediaCollection.ShortTitle      = collectionNode.Attributes["ShortTitle"].Value.ToString();
                mediaCollection.Title           = collectionNode.Attributes["Title"].Value.ToString();
                mediaCollection.Location        = collectionNode.Attributes["Location"].Value.ToString();

                int Id = 1;
                List<MediaElement> mediaElements = new List<MediaElement>();
                foreach (XmlNode elementNode in collectionNode)
                {
                    MediaElement mediaElement = new MediaElement();
                    mediaElement.CollectionId = CollectionId;
                    mediaElement.Id = Id++;
                    mediaElement.File = elementNode.Attributes["fileName"].Value.ToString();

                    mediaElements.Add(mediaElement);
                }

                mediaCollection.MediaElements   = mediaElements;

            return mediaCollection;
        }
 public void AddMediaCollectionDescription(MediaCollection MediaCollection)
 {
     db.MediaCollections.Add(MediaCollection);
     db.SaveChanges();
 }