public void AddMedia(MediaElement Media)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionString);
            NpgsqlCommand command = new NpgsqlCommand(@"INSERT INTO dbo.""MediaElements"" (CollectionId, File) VALUES (:CollectionId, :File)", connection);

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

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
        public void AddMedia(MediaElement Media)
        {
            XmlDocument XMLfile = new XmlDocument();
            XMLfile.Load(XMLDescriptionFile);

            XmlElement node_mediaElement = XMLfile.CreateElement("item");
            XmlAttribute attr_fileName = XMLfile.CreateAttribute("fileName");
            attr_fileName.Value = Media.File;
            node_mediaElement.Attributes.Append(attr_fileName);

            XMLfile.DocumentElement.LastChild.InsertAfter(node_mediaElement, XMLfile.DocumentElement.LastChild.LastChild);

            XMLfile.Save(XMLDescriptionFile);
        }
Exemplo n.º 3
0
        //[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 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 List<MediaElement> GetMediaCollection(int CollectionId)
        {
            XmlDocument XMLStore = new XmlDocument();
            XMLStore.Load(XMLDescriptionFile);
            XmlNodeList root = XMLStore.DocumentElement.ChildNodes;

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

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

                mediaElements.Add(mediaElement);
            }

            return mediaElements;
        }
 public void AddMedia(MediaElement Media)
 {
     db.MediaElements.Add(Media);
     db.SaveChanges();
 }
 public void AddMedia(MediaElement Media)
 {
     medias.Add(Media);
 }
        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 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<MediaElement> GetMediaCollection(int CollectionId)
        {
            NpgsqlConnection connection = new NpgsqlConnection(connectionString);
            NpgsqlCommand command = new NpgsqlCommand(@"SELECT * FROM dbo.""MediaElements"" WHERE CollectionId = :CollectionId", connection);
            command.Parameters.Add(new NpgsqlParameter("CollectionId", NpgsqlDbType.Integer));
            command.Parameters[0].Value = CollectionId;

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

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

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

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

            connection.Close();

            return mediaelements;
        }