示例#1
0
 public static CITITOR AddCititor(InregistrareCititor cititor)
 {
     try
     {
         using (var context = new BibliotecaModelContainer())
         {
             var reader = context.CITITORs.FirstOrDefault(p =>
                                                          p.Prenume == cititor.Prenume && p.Nume == cititor.Nume && p.Adresa == cititor.Adresa &&
                                                          p.Email == cititor.Email);
             if (reader == null)
             {
                 var newCititor = new CITITOR
                 {
                     Nume    = cititor.Nume,
                     Prenume = cititor.Prenume,
                     Adresa  = cititor.Adresa,
                     Email   = cititor.Email,
                     Stare   = 0
                 };
                 context.CITITORs.Add(newCititor);
                 context.SaveChanges();
                 return(newCititor);
             }
             return(reader);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.InnerException.Message);
         return(null);
     }
 }
示例#2
0
 public static bool ImprumutaCartea(CITITOR cititor, string titlu, string autorNume, string autorPrenume, int numerZile)
 {
     try
     {
         using (var context = new BibliotecaModelContainer())
         {
             var autor  = context.AUTORs.FirstOrDefault(p => p.Nume == autorNume && p.Prenume == autorPrenume);
             var cartea = context.CARTEs.FirstOrDefault(p => p.AutorId == autor.AutorId && p.Titlu == titlu);
             if (autor == null || cartea == null)
             {
                 return(false);
             }
             var imprumut = new IMPRUMUT
             {
                 CarteId      = cartea.CarteId,
                 CititorId    = cititor.CititorId,
                 DataImprumut = DateTime.Now,
                 DataScadenta = DateTime.Now.AddDays(numerZile)
             };
             context.IMPRUMUTs.Add(imprumut);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#3
0
 public static bool PotRestituiiCartea(CITITOR cititor, int carteId)
 {
     try
     {
         using (var context = new BibliotecaModelContainer())
         {
             var result = context.IMPRUMUTs.FirstOrDefault(p => p.CarteId == carteId && p.CititorId == cititor.CititorId && p.DataRestituire == null);
             if (result == null)
             {
                 return(false);
             }
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
示例#4
0
        public static bool RestituieCarte(CITITOR cititor, int carteId, string textReview)
        {
            try
            {
                using (var context = new BibliotecaModelContainer())
                {
                    var result = context.IMPRUMUTs.FirstOrDefault(p => p.CarteId == carteId && p.CititorId == cititor.CititorId && p.DataRestituire == null);
                    if (result == null)
                    {
                        return(false);
                    }
                    result.DataRestituire = DateTime.Now;
                    context.IMPRUMUTs.AddOrUpdate(result);

                    var imprumuturiPesteLimita = context.IMPRUMUTs
                                                 .Count(p => p.CititorId == cititor.CititorId && p.DataScadenta < p.DataRestituire);
                    if (imprumuturiPesteLimita > 2)
                    {
                        cititor.Stare = 1;
                        context.CITITORs.AddOrUpdate(cititor);
                    }

                    var review = new REVIEW
                    {
                        ImprumutId = result.ImprumutId,
                        Text       = textReview
                    };
                    context.REVIEWs.Add(review);
                    context.SaveChanges();
                    return(true);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }