public IHttpActionResult Put()
        {
            try
            {
                using (MusicFileEntities entites = new MusicFileEntities())
                {
                    Models.MusicFileJson musicFile =
                        new Models.MusicFileJson(Request.Content.ReadAsStringAsync().Result);
                    // check if the genre is valid
                    if (!(musicFile.Genre == "Pop" || musicFile.Genre == "Rock" || musicFile.Genre == "Dance" ||
                          musicFile.Genre == "Latin"))
                    {
                        return(Ok("Not a correct genre"));
                    }

                    var join = (from m in entites.MusicFile
                                join title in entites.Title
                                on m.Title equals title.ID
                                select new
                    {
                        ID = m.ID, Title = new Models.TitleDTO {
                            ID = title.ID, Name = title.NAME
                        },
                        Interpret = m.Interpret, Genre = title.Genre
                    });

                    // check if the interpret already exists in the database
                    var preInterpret = entites.Interpret.FirstOrDefault(i => i.NAME == musicFile.Interpret.Name);
                    Models.InterpretDTO createdInterpret = new Models.InterpretDTO {
                        ID = 0, Name = ""
                    };
                    if (preInterpret != null)
                    {
                        createdInterpret.ID   = preInterpret.ID;
                        createdInterpret.Name = preInterpret.NAME;
                        // check if the interpret already has a title named like the musicfile
                        var tempTitle = join.FirstOrDefault(m =>
                                                            m.Interpret == createdInterpret.ID && m.Title.Name == musicFile.Title.Name &&
                                                            m.Title.ID != musicFile.Title.ID);
                        if (tempTitle != null)
                        {
                            return(Ok("The interpret " + createdInterpret.Name + " has already a title named like " +
                                      musicFile.Title.Name));
                        }
                    }
                    else
                    {
                        //create new interpret
                        MusicFileDataAccess.Interpret interpret = new MusicFileDataAccess.Interpret();
                        interpret.NAME = musicFile.Interpret.Name;
                        entites.Interpret.Add(interpret);
                        entites.SaveChanges();
                        // after the creation get the newly id of the interpret
                        createdInterpret = entites.Interpret.Select(i => new Models.InterpretDTO()
                        {
                            ID   = i.ID,
                            Name = i.NAME
                        }).SingleOrDefault(i => i.Name == musicFile.Interpret.Name);
                    }

                    var existingTitle = entites.Title.FirstOrDefault(t => t.ID == musicFile.Title.ID);
                    if (existingTitle != null)
                    {
                        existingTitle.NAME  = musicFile.Title.Name;
                        existingTitle.Genre = musicFile.Genre;
                        entites.SaveChanges();

                        var existingMusicFile = entites.MusicFile.FirstOrDefault(m => m.ID == musicFile.ID);

                        if (existingMusicFile != null)
                        {
                            existingMusicFile.Interpret = createdInterpret.ID;
                            entites.SaveChanges();
                        }
                        else
                        {
                            return(NotFound());
                        }
                    }
                    else
                    {
                        return(NotFound());
                    }

                    return(Ok("Successfully updated!"));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }
        public IHttpActionResult Post()
        {
            try
            {
                using (MusicFileEntities entites = new MusicFileEntities())
                {
                    Models.MusicFileJson musicFile =
                        new Models.MusicFileJson(Request.Content.ReadAsStringAsync().Result);
                    // check if the genre is valid
                    if (!(musicFile.Genre == "Pop" || musicFile.Genre == "Rock" || musicFile.Genre == "Dance" ||
                          musicFile.Genre == "Latin"))
                    {
                        return(Ok("Not a correct genre"));
                    }

                    //System.Diagnostics.Debug.WriteLine(musicFile.Title.Name);
                    var join = (from m in entites.MusicFile
                                join title in entites.Title
                                on m.Title equals title.ID
                                select new
                    {
                        ID = m.ID, Title = new Models.TitleDTO {
                            ID = title.ID, Name = title.NAME
                        },
                        Interpret = m.Interpret, Genre = title.Genre
                    });

                    // check if the title is already in the database
                    var element = join.FirstOrDefault(m =>
                                                      m.Title.Name == musicFile.Title.Name && m.Interpret == musicFile.Interpret.ID);
                    if (element == null)
                    {
                        //First Create the title
                        MusicFileDataAccess.Title title = new MusicFileDataAccess.Title();
                        title.NAME  = musicFile.Title.Name;
                        title.Genre = musicFile.Genre;
                        entites.Title.Add(title);
                        entites.SaveChanges();
                        // get the Title ID
                        Models.TitleDTO createdTitle = entites.Title.Select(i => new Models.TitleDTO()
                        {
                            ID   = i.ID,
                            Name = i.NAME
                        }).OrderByDescending(t => t.ID).FirstOrDefault(i => i.Name == musicFile.Title.Name);
                        System.Diagnostics.Debug.WriteLine(createdTitle.ID);

                        // if the interpret is not in the database, create a new interpret
                        var existingInterpret =
                            entites.Interpret.FirstOrDefault(i => i.NAME == musicFile.Interpret.Name);
                        Models.InterpretDTO createdInterpret = new Models.InterpretDTO
                        {
                            ID = musicFile.Interpret.ID, Name = musicFile.Interpret.Name
                        };
                        if (existingInterpret == null)
                        {
                            MusicFileDataAccess.Interpret interpret = new MusicFileDataAccess.Interpret();
                            interpret.NAME = musicFile.Interpret.Name;
                            entites.Interpret.Add(interpret);
                            entites.SaveChanges();
                            // after the creation get the newly id of the interpret
                            createdInterpret = entites.Interpret.Select(i => new Models.InterpretDTO()
                            {
                                ID   = i.ID,
                                Name = i.NAME
                            }).SingleOrDefault(i => i.Name == musicFile.Interpret.Name);
                        }

                        System.Diagnostics.Debug.WriteLine(createdTitle.ID);
                        //in the last step create the music file
                        MusicFileDataAccess.MusicFile createdMusicFile = new MusicFileDataAccess.MusicFile();
                        createdMusicFile.Title     = createdTitle.ID;
                        createdMusicFile.Interpret = createdInterpret.ID;
                        entites.MusicFile.Add(createdMusicFile);
                        entites.SaveChanges();

                        // return success message
                        return(Ok("Music file successfully created!"));
                    }
                    else
                    {
                        return(Ok("Element is already in the database"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest());
            }
        }