Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8675213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:53:48+00:00 2026-06-12T19:53:48+00:00

Here is Index: It goes through folder and should add entries to database. But

  • 0

Here is Index:
It goes through folder and should add entries to database. But when i run it no entries are getting added. Is something wrong with this code?
(Basically code goes through couple folders gets image file and songs under the folder and add to database, but it is not working.)

public ActionResult Index()
        {            
            DemoDb db = new DemoDb();
            var movies = new List<SongModel>();
            MovieModel movie = new MovieModel();
            SongModel song = new SongModel();
            //Function to get all the folders present in that particular location,Use
            var folders = Directory.GetDirectories(Server.MapPath("~/Content/themes/base/songs"));

            foreach (var folder in folders)
            {
                movie.MovieName = new DirectoryInfo(folder).Name;
                string[] files = Directory.GetFiles(folder);
                string img = string.Empty;
                var list = new List<string>();
                foreach (var file in files)
                {
                    if (Path.GetExtension(file) == ".jpg" ||
                        Path.GetExtension(file) == ".png")
                    {
                        movie.Image = Path.Combine(Server.MapPath("~/Content/themes/base/songs"), file);
                    }
                    else
                    {
                        song.MovieId = movie.MovieId;
                        song.Song = Path.Combine(Server.MapPath("~/Content/themes/base/songs"), file);                        
                    }     
                }
                db.movies.Add(movie);
                db.songs.Add(song);
                db.SaveChanges();
            }              
            return View();
        }

Here are classes and database design too:

public class MovieModel
    {
        [Key]
        public int MovieId { get; set; }
        public string MovieName { get; set; }
        public int SongId { get; set; }
        public string Image { get; set; }
    }
    public class SongModel
    {
        [Key]
        public int SongId { get; set; }
        public int MovieId { get; set; }
        public string Song { get; set; }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:53:49+00:00Added an answer on June 12, 2026 at 7:53 pm

    You are creating only one movie and song above.
    For every folder you overwrite the values in a movie object but never add a new object to your context, you only try to re-add your existing movie.
    Also I wouldn’t do this on an index HttpGet method. By the http spec a repeated GET call shouldn’t change the system state each time (hence it should be idempotent)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I stumbled upon Jtalk here http://nicolaspetton.github.com/jtalk/index.html#download but when clicking on download I have 404
I'm trying to add a custom catalog index based on the recommendation here: http://collective-docs.readthedocs.org/en/latest/searching_and_indexing/indexing.html#custom-index-methods
Here's what I'm trying to achieve: Before: www.example.com/index.php?page=about&pg=5 After: www.example.com/about.html?pg=5 The URL must specifically
Here in this code: $('#doneItem').click(function(){ $(this).each(function(index){ var item = 'personal' + index; alert(item); localStorage.removeItem('personal'
Here's the code in AlertTableView: - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSInteger index = 12345; NSLog(@AlertTableView:
I am trying to get index of each items in a listbox Here is
Here is my try: @header(Content-type: text/html; charset=utf-8); @header(Location:/index.php); @header(Cache-Control: no-cache, must-revalidate); // HTTP/1.1 @header(Expires:
You can see my project here - http://www.inluxphoto.com/custom/jsgallery/index.php I am attempting to make the
Part-time reluctant DBA here. I want to change an existing primary key index from
I have this query that (stripped right down) goes something like this : SELECT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.