Пример #1
0
        public bool AddDiscBand(SellInfo sellInfo)
        {
            //Band band = new Band();
            //if (context.Bands.Any(p => p.Name == sellInfo.BandName))
            //{
            //    band = context.Bands.FirstOrDefault(p => p.Name == sellInfo.BandName);
            //}
            //else band = new Band { Name = sellInfo.BandName, Year = sellInfo.BandDate };
            try
            {
                AddDisc(sellInfo, AddBand(sellInfo.BandName, sellInfo.BandDate));
            }
            catch (Exception)
            {
                return(false);
            }
            //context.CDs.Add(
            //    new CD
            //    {
            //        Name = sellInfo.CDName,
            //        Cd_Date = sellInfo.Cd_Date,
            //        Format = context.Formats.FirstOrDefault(f => f.Name == sellInfo.FormatName),
            //        Band = band
            //    });
            //context.SaveChanges();

            return(true);
        }
Пример #2
0
 private void AddDisc(SellInfo sellInfo, Band band)
 {
     using (DiscContext context = new DiscContext())
     {
         context.CDs.Add(
             new CD
         {
             Name    = sellInfo.CDName,
             Cd_Date = sellInfo.Cd_Date,
             Format  = context.Formats.FirstOrDefault(f => f.Name == sellInfo.FormatName),
             Band    = band
         });
         context.SaveChanges();
     }
 }