コード例 #1
0
 public IEnumerable <SongModel> GetAllSongs()
 {
     using (var ctx = new MmDbContext())
     {
         return(ctx.Songs.Select(it => ModelFromEntity(it)).ToList());
     }
 }
コード例 #2
0
        public async Task <int> AddSong(string name, Stream file)
        {
            var filePath = generateFilePath();

            try
            {
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    file.Seek(0, SeekOrigin.Begin);
                    file.CopyTo(stream);
                }
            }
            catch
            {
                return(-1);
            }


            using (var ctx = new MmDbContext())
            {
                var song = new Song()
                {
                    Name = name, Path = filePath
                };
                ctx.Songs.Add(song);
                await ctx.SaveChangesAsync().ConfigureAwait(false);

                return(song.Id);
            }
        }
コード例 #3
0
        public async Task <bool> RemoveSong(int id)
        {
            using (var ctx = new MmDbContext())
            {
                var item = ctx.Songs.FirstOrDefault(it => it.Id == id);
                if (item == null)
                {
                    return(false);
                }

                var path = item.Path;

                // Даже если файлы уже дулаены вручную, удаляем запись из БД
                try
                {
                    File.Delete(path);
                }
                finally
                {
                    var del = ctx.Songs.FirstOrDefault(it => it.Id == id);
                    ctx.Remove(del);
                    await ctx.SaveChangesAsync().ConfigureAwait(false);
                }
            }

            return(true);
        }
コード例 #4
0
 public bool ContainsSong(int id)
 {
     using (var ctx = new MmDbContext())
     {
         return(ctx.Songs.Any(it => it.Id == id));
     }
 }
コード例 #5
0
ファイル: Startup.cs プロジェクト: Compufreak345/MatchMaker
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, MmDbContext dbContext)
        {
            dbContext.Database.Migrate();
            app.UseForwardedHeaders();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

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

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseMiddleware <UserProviderMiddleware>();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                endpoints.MapHub <NotificationHub>("/notificationHub");
            });
        }
コード例 #6
0
        public SongModel GetSongById(int id)
        {
            using (var ctx = new MmDbContext())
            {
                var song = ctx.Songs.FirstOrDefault(it => it.Id == id);

                return(ModelFromEntity(song));
            }
        }
コード例 #7
0
        public CityGroupViewModel(int id)
        {
            var db = new MmDbContext();
            var cg = db.CityGroups.Where(g => g.GroupId == id).FirstOrDefault();

            this.GroupId       = cg.GroupId;
            this.GroupName     = cg.GroupName;
            this.CityIds       = cg.CityIds;
            this.IncludedCitys = new List <City>();
            this.IncludedCitys = db.Citys.SqlQuery("SELECT Id, City as Name, StateId FROM dbo.CityMaster where id in (" + CityIds + ")").ToList <City>();
            IncludedCitys.ForEach(city => { city.State = db.States.Find(city.StateId); });
        }
コード例 #8
0
        public byte[] GetSongStream(int id)
        {
            string filePath;

            using (var ctx = new MmDbContext())
            {
                filePath = ctx.Songs.FirstOrDefault(it => it.Id == id).Path;
            }

            using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
            {
                var result = new byte[stream.Length];
                stream.Read(result, 0, result.Length);

                return(result);
            }
        }
コード例 #9
0
        public CreditCardViewModel()
        {
            MmDbContext db = new MmDbContext();

            ReasonsToGetThisCard = new List <string>()
            {
                string.Empty
            };
            BanksSelectList = db.Banks.Select(x => new SelectListItem
            {
                Value = x.BankId.ToString(),
                Text  = x.Name,
            }).ToList();
            _BenefitsAndFeature = new List <BenefitsAndFeature>()
            {
                new BenefitsAndFeature()
                {
                    HeadingText = string.Empty, Points = new List <string>(),
                }
            };
            _RedeemReward = new List <RedeemReward>()
            {
                new RedeemReward()
                {
                    HeadingText = string.Empty, Points = new List <string>(),
                }
            };
            _FeesAndCharge = new List <FeesAndCharge>()
            {
                new FeesAndCharge()
                {
                    HeadingText = string.Empty, Points = new List <KeyValuePair <string, string> >(),
                }
            };
            _BorrowPrivilege = new List <BorrowPrivilege>()
            {
                new BorrowPrivilege()
                {
                    HeadingText = string.Empty, SubHeadingText = string.Empty, Points = new List <KeyValuePair <string, string> >(),
                }
            };
            EligibilityCriteria = new List <EligibilityCriteria> {
                new EligibilityCriteria()
            };
        }
コード例 #10
0
 public UserRepository(MmDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
コード例 #11
0
        public CreditCardViewModel(int CardId)
        {
            MmDbContext db    = new MmDbContext();
            var         cCard = db.CreditCards.Where(cc => cc.CardId == CardId).SingleOrDefault();

            BankId          = cCard.BankId;
            this.CardId     = cCard.CardId;
            BanksSelectList = db.Banks.Select(x => new SelectListItem
            {
                Value    = x.BankId.ToString(),
                Text     = x.Name,
                Selected = (x.BankId == BankId) ? true : false,
            }).ToList();
            CardName        = cCard.CardName;
            CardDescription = cCard.CardDescription;
            CardImageUrl    = cCard.CardImageUrl;
            BankName        = cCard.Bank.Name;
            var CcDetail = db.CcDetails.Where(cc => cc.CardId == CardId).OrderBy(cc => cc.CcInfoSectionMasterId).ThenBy(cc => cc.Heading);

            _BenefitsAndFeature = new List <BenefitsAndFeature>()
            {
            };
            _FeesAndCharge = new List <FeesAndCharge>()
            {
            };
            _RedeemReward = new List <RedeemReward>()
            {
            };
            _BorrowPrivilege = new List <BorrowPrivilege>()
            {
            };
            ReasonsToGetThisCard = new List <string>()
            {
            };
            foreach (var r in CcDetail.Where(ccd => ccd.CcInfoSectionMaster.CcInfoSectionMasterId == 1))
            {
                ReasonsToGetThisCard.Add(r.Point);
            }
            foreach (var bf in CcDetail.Where(ccd => ccd.CcInfoSectionMaster.CcInfoSectionMasterId == 2))
            {
                if (_BenefitsAndFeature.Count == 0 || _BenefitsAndFeature.Last().HeadingText != bf.Heading)
                {
                    _BenefitsAndFeature.Add(new BenefitsAndFeature()
                    {
                        HeadingText = bf.Heading, Points = new List <string>()
                        {
                            bf.Point
                        }
                    });
                }
                else
                {
                    _BenefitsAndFeature.LastOrDefault().Points.Add(bf.Point);
                }
            }
            foreach (var bf in CcDetail.Where(ccd => ccd.CcInfoSectionMaster.CcInfoSectionMasterId == 3))
            {
                if (_FeesAndCharge.Count == 0 || _FeesAndCharge.Last().HeadingText != bf.Heading)
                {
                    _FeesAndCharge.Add(new FeesAndCharge()
                    {
                        HeadingText = bf.Heading,
                        Points      = new List <KeyValuePair <string, string> >()
                        {
                            new KeyValuePair <string, string>(bf.Key_, bf.Value)
                        }
                    });
                }
                else
                {
                    _FeesAndCharge.LastOrDefault().Points.Add(new KeyValuePair <string, string>(bf.Key_, bf.Value));
                }
            }
            foreach (var bf in CcDetail.Where(ccd => ccd.CcInfoSectionMaster.CcInfoSectionMasterId == 4))
            {
                if (_RedeemReward.Count == 0 || _RedeemReward.Last().HeadingText != bf.Heading)
                {
                    _RedeemReward.Add(new RedeemReward()
                    {
                        HeadingText = bf.Heading, Points = new List <string>()
                        {
                            bf.Point
                        }
                    });
                }
                else
                {
                    _RedeemReward.LastOrDefault().Points.Add(bf.Point);
                }
            }
            foreach (var bf in CcDetail.Where(ccd => ccd.CcInfoSectionMaster.CcInfoSectionMasterId == 5))
            {
                if (_BorrowPrivilege.Count == 0 || _BorrowPrivilege.Last().HeadingText != bf.Heading)
                {
                    _BorrowPrivilege.Add(new BorrowPrivilege()
                    {
                        HeadingText    = bf.Heading,
                        SubHeadingText = bf.Point,
                        Points         = new List <KeyValuePair <string, string> >()
                        {
                            new KeyValuePair <string, string>(bf.Key_, bf.Value)
                        }
                    });
                }
                else
                {
                    _BorrowPrivilege.LastOrDefault().Points.Add(new KeyValuePair <string, string>(bf.Key_, bf.Value));
                }
            }
            if (db.CcEligibilityCriterias.Any(ec => ec.CardId == cCard.CardId))
            {
                EligibilityCriteria = db.CcEligibilityCriterias.Where(ec => ec.CardId == cCard.CardId).ToList();
            }
        }