Esempio n. 1
0
        public string manage_song([FromBody] string value)
        {
            bool IsRemove = value.Substring(0, 2) == "--";
            var  title    = IsRemove ? value.Substring(2, value.Length - 2) : value;

            if (HttpContext.Session.GetString("Admin") == "True" && title.Trim() != String.Empty)
            {
                if (IsRemove)
                {
                    using (var db = new SongContext()){
                        Song song = db.Songs.FirstOrDefault(b => b.Id == int.Parse(title));
                        if (song != null)
                        {
                            db.Songs.Remove(song);
                            db.SaveChanges();
                            return($"Removed: {song.Title}");
                        }
                    }
                    return($"Not Found");
                }
                else
                {
                    using (var db = new SongContext()){
                        Song newsong = new Song();
                        newsong.Title = title;
                        db.Songs.Add(newsong);
                        db.SaveChanges();
                    }
                    return($"Added: {title}");
                }
            }
            return("No Change.");
        }
Esempio n. 2
0
 public ValuesController(SongContext songContext,
                         IFreeSql orm1, IFreeSql orm2,
                         IFreeSql <long> orm3
                         )
 {
     _orm = orm1;
 }
Esempio n. 3
0
 static void TestEfSelectPatientExamination_2022()
 {
     using (var ctx = new SongContext())
     {
         var list = ctx.PatientExamination_2022s.Take(40000).AsNoTracking().ToList();
     }
 }
Esempio n. 4
0
        public static void EnsureSeedDataForContext(this SongContext context)
        {
            if (context.Songs.Any())
            {
                return;
            }

            var songs = new List <Song>()
            {
                new Song()
                {
                    Name       = "Błogosławieni Miłosierni",
                    YouTubeUrl = @"www.youtube.com/Blogoslawnie"
                },

                new Song()
                {
                    Name       = "Barka",
                    YouTubeUrl = @"www.youtube.com/Barka"
                }
            };

            context.Songs.AddRange(songs);
            context.SaveChanges();
        }
Esempio n. 5
0
        public IQueryable <Category> GetCategories()
        {
            var _db = new SongContext();
            IQueryable <Category> query = _db.Categories;

            return(query);
        }
Esempio n. 6
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, SongContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            db.Database.Migrate();

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseSwagger();
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "The Song List v1");
            });

            app.UseAuthentication().UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Esempio n. 7
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory,
                              SongContext songContext)
        {
            loggerFactory.AddConsole();
            loggerFactory.AddDebug();
            loggerFactory.AddNLog();

            songContext.EnsureSeedDataForContext();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }


            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            app.UseStatusCodePages();


            Mapper.Initialize(cfg =>
            {
                cfg.CreateMap <Song, SongDto>();
                cfg.CreateMap <SongForCreationDto, Song>();
                cfg.CreateMap <Song, SongForUpdateDto>();
                cfg.CreateMap <SongForUpdateDto, Song>();
                cfg.CreateMap <Presentation, PresentationDto>()
                .ForMember(dest => dest.CreatedDate,
                           opt => opt.MapFrom(src =>
                                              src.CreatedDate.ToString("dddd, dd MMMM yyyy", CultureInfo.CreateSpecificCulture("pl-pl"))))
                .ForMember(dest => dest.UrlToPptx,
                           opt => opt.MapFrom(src =>
                                              UrlToPptxFile(src)))
                .ForMember(dest => dest.UrlToZip,
                           opt => opt.MapFrom(src =>
                                              UrlToDownloadedFile(src)))
                .ForMember(dest => dest.SongNames,
                           opt => opt.MapFrom(src =>
                                              src.LinkSongToPresentation.Select(song => Path.GetFileName(song.Song.Name))));
            });

            DefaultFilesOptions options = new DefaultFilesOptions();

            options.DefaultFileNames.Clear();
            options.DefaultFileNames.Add("login.html");
            app.UseDefaultFiles(options);
            app.UseStaticFiles();


            app.UseAuthentication();
            app.UseCors("AllowAll");
            app.UseMvc();


            app.Run(async(context) =>
            {
                await context.Response.WriteAsync("No cześć! A Ty co tutaj robisz :)?");
            });
        }
Esempio n. 8
0
 public IActionResult Post([FromBody] SongRequest value)
 {
     using (var db = new SongContext()){
         db.SongRequests.Add(value);
         db.SaveChanges();
     }
     return(StatusCode(201, value));
 }
Esempio n. 9
0
 public IActionResult Delete(long id)
 {
     using (var db = new SongContext()){
         SongRequest song = db.SongRequests.FirstOrDefault(b => b.Id == id);
         db.SongRequests.Remove(song);
         db.SaveChanges();
     }
     return(StatusCode(201, id));
 }
Esempio n. 10
0
        public IEnumerable <SongRequest> Get()
        {
            IEnumerable <SongRequest> results;

            using (var db = new SongContext()){
                IEnumerable <SongRequest> songs = db.SongRequests.Where(b => b.Viewed == false);
                results = songs.ToList();
            }
            return(results);
        }
Esempio n. 11
0
        private void changeSong()
        {
            this._mediaFoundationReader = new MediaFoundationReader(this._songManager.GetNextSong());
            this._sampleAggregator.SetSource(this._mediaFoundationReader.ToSampleProvider());

            if (SongContextEventHandler != null)
            {
                SongContext songContext = this._songManager.GetSongContext();
                SongContextEventHandler.Invoke(this, songContext);
            }
        }
Esempio n. 12
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            SongContext db = new SongContext();
            db.Database.Initialize(false);
            db.SaveChanges();
            db.Dispose();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Esempio n. 13
0
        public void Play()
        {
            if (this._playbackDevice != null && this._sampleAggregator != null && this._playbackDevice.PlaybackState != PlaybackState.Playing)
            {
                this._playbackDevice.Play();
            }

            if (SongContextEventHandler != null)
            {
                SongContext songContext = this._songManager.GetSongContext();
                SongContextEventHandler.Invoke(this, songContext);
            }
        }
Esempio n. 14
0
 public IActionResult Kick(long id)
 {
     using (var db = new SongContext()){
         SongRequest song = db.SongRequests.FirstOrDefault(b => b.Id == id);
         db.SongRequests.Remove(song);
         SongRequest newSong = new SongRequest();
         newSong.Singer = song.Singer;
         newSong.Song   = song.Song;
         db.SongRequests.Add(newSong);
         db.SaveChanges();
     }
     return(StatusCode(201, id));
 }
Esempio n. 15
0
 public void addSong(string name, string artist, int BPM)
 {
     using (var db = new SongContext())
     {
         var song = new Song
         {
             Name   = name,
             Artist = artist,
             bpm    = BPM
         };
         db.Songs.Add(song);
         db.SaveChanges();
     }
 }
Esempio n. 16
0
        static void Update(StringBuilder sb, int forTime, int size)
        {
            Stopwatch sw = new Stopwatch();

            var songs = fsql.Select <Song>().Limit(size).ToList();

            sw.Restart();
            for (var a = 0; a < forTime; a++)
            {
                fsql.Update <Song>().SetSource(songs).ExecuteAffrows();
            }
            sw.Stop();
            sb.AppendLine($"FreeSql Update {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms");

            songs = sugar.Queryable <Song>().Take(size).ToList();
            sw.Restart();
            Exception sugarEx = null;

            try
            {
                for (var a = 0; a < forTime; a++)
                {
                    sugar.Updateable(songs).ExecuteCommand();
                }
            }
            catch (Exception ex)
            {
                sugarEx = ex;
            }
            sw.Stop();
            sb.AppendLine($"SqlSugar Update {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms" + (sugarEx != null ? $"成绩无效,错误:{sugarEx.Message}" : ""));

            using (var db = new SongContext())
            {
                songs = db.Songs.Take(size).AsNoTracking().ToList();
            }
            sw.Restart();
            for (var a = 0; a < forTime; a++)
            {
                using (var db = new SongContext())
                {
                    //db.Configuration.AutoDetectChangesEnabled = false;
                    //db.Songs.UpdateRange(songs.ToArray());
                    //db.SaveChanges();
                }
            }
            sw.Stop();
            sb.AppendLine($"EFCore Update {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms .net5.0无效\r\n");
        }
Esempio n. 17
0
        private static void MusicService_MusicContextEventHandler(object sender, SongContext e)
        {
            if (e == null)
            {
                return;
            }

            Console.SetCursorPosition(0, 0);
            Console.ForegroundColor = ConsoleColor.Cyan;

            Console.WriteLine("---------------------");
            Console.WriteLine($"Next |{ e.NextName }");
            Console.WriteLine($"Now  |{ e.MusicName}");
            Console.WriteLine("---------------------");
        }
Esempio n. 18
0
 public SongsController(SongContext context)
 {
     _context = context;
     if (_context.SongList.Count() == 0)
     {
         _context.SongList.Add(new Song {
             Id       = 1,
             Name     = "Solitary Man",
             Duration = 123,
             Album    = "American III: Solitary Man",
             Artist   = "Johnny Cash"
         });
         _context.SaveChanges();
     }
 }
Esempio n. 19
0
        public List <string[]> selectSong()
        {
            List <string[]> songs = new List <string[]>();

            string[] parts;
            using (var db = new SongContext())
            {
                var query = from s in db.Songs orderby s.songId select s;
                foreach (var item in query)
                {
                    parts = new string[] { $"{item.Name}", $"{item.Artist}", $"{item.bpm}" };
                    songs.Add(parts);
                }
                return(songs);
            }
        }
Esempio n. 20
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);

//
//---------------- den här gör att det går att lagra info
            using (var ctx = new SongContext())
            {
                Artist art = new Artist()
                {
                    Name = "new artist"
                };
                ctx.Artists.Add(art);
                ctx.SaveChanges();
            }
//
//--------------------------------------------------------
        }
Esempio n. 21
0
        static void Select(StringBuilder sb, int forTime, int size)
        {
            Stopwatch sw = new Stopwatch();

            sw.Restart();
            for (var a = 0; a < forTime; a++)
            {
                fsql.Select <Song>().Limit(size).ToList();
            }
            sw.Stop();
            sb.AppendLine($"FreeSql Select {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms");

            sw.Restart();
            for (var a = 0; a < forTime; a++)
            {
                sugar.Queryable <Song>().Take(size).ToList();
            }
            sw.Stop();
            sb.AppendLine($"SqlSugar Select {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms");

            sw.Restart();
            for (var a = 0; a < forTime; a++)
            {
                using (var db = new SongContext())
                {
                    //db.Songs.Take(size).AsNoTracking().ToList();
                }
            }
            sw.Stop();
            sb.AppendLine($"EFCore Select {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms .net5.0无效");

            sw.Restart();
            using (var conn = fsql.Ado.MasterPool.Get())
            {
                for (var a = 0; a < forTime; a++)
                {
                    Dapper.SqlMapper.Query <Song>(conn.Value, $"select top {size} * from freesql_song").ToList();
                }
            }
            sw.Stop();
            sb.AppendLine($"Dapper Select {size}条数据,循环{forTime}次,耗时{sw.ElapsedMilliseconds}ms\r\n");
        }
 //Method to download the file and return them in an filecontent file--would explain later,please dont edit anything for now on it.
 public FileContentResult DownloadFile(int?id)
 {
     //  ProjectOneContext is your file list DB context with FileName property
     using (SongContext db = new SongContext())
     {
         var download = db.Files.Where(x => x.FileId == id).SingleOrDefault();
         if (download != null)
         {
             // String mimeType = MimeMapping.GetMimeMapping(download.FileName);
             // remove this line if you want file download on the same page
             Response.AddHeader("content-disposition", "inline; filename=" + download.FileName);
             return(File(download.Content, "audio/mpeg" /*, mimeType*/));
             // MimeMapping.GetMimeMapping(filepath)
         }
         else
         {
             return(null);
         }
     }
 }
Esempio n. 23
0
        public IEnumerable <Song> find_songs([FromBody] string value)
        {
            IEnumerable <Song> results;

            if (value == AppSettingsProvider.AdminKey)
            {
                HttpContext.Session.SetString("Admin", "True");

                List <Song> dummy = new List <Song>();
                Song        sng   = new Song();
                sng.Id    = 777;
                sng.Title = "God Mode Unlocked";
                dummy.Add(sng);
                return(dummy);
            }

            using (var db = new SongContext()){
                IEnumerable <Song> songs = db.Songs.Where(b => b.Title.Contains(value)).Take(100);
                results = songs.OrderBy(s => s.Title).ToList();
            }

            return(results);
        }
Esempio n. 24
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="songContext">The song context comes from Dependency Injection.</param>
 public SongRepository(SongContext songContext)
 => SongContext = songContext;
 public AppearancesController(SongContext context)
 {
     _context = context;
 }
 public ArtistsController(SongContext context)
 {
     _context = context;
 }
 public SeasonsController(SongContext context)
 {
     _context = context;
 }
 public SongController(SongContext ctx)
 {
     context = ctx;
 }
Esempio n. 29
0
 public SongsController(SongContext context)
 {
     _context = context;
 }
Esempio n. 30
0
 public EpisodesController(SongContext context)
 {
     _context = context;
 }