Esempio n. 1
0
 public BOOK EditBook(BOOK eBook)
 {
     using (DbLibrary db = new DbLibrary())
     {
         db.Configuration.LazyLoadingEnabled = false;
         BOOK book = db.BOOKs.Include(b => b.AUTHORs).FirstOrDefault(x => x.ISBN.Equals(eBook.ISBN));
         book.AUTHORs.Clear();
         db.SaveChanges();
     }
     using (DbLibrary db = new DbLibrary())
     {
         db.Configuration.LazyLoadingEnabled = false;
         BOOK book = db.BOOKs.Include(b => b.CLASSIFICATION).FirstOrDefault(x => x.ISBN.Equals(eBook.ISBN));
         db.Entry(book).CurrentValues.SetValues(eBook);
         db.ChangeTracker.Entries <CLASSIFICATION>().ToList().ForEach(a => a.State = EntityState.Unchanged);
         book.AUTHORs = new List <AUTHOR>();
         foreach (var author in eBook.AUTHORs)
         {
             db.AUTHORs.Attach(author);
             book.AUTHORs.Add(author);
         }
         db.SaveChanges();
         return(book);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Agrega un nuevo registro a la entidad de roles
        /// </summary>
        /// <param name="systemRol"></param>
        /// <returns></returns>
        public Operations Create(SystemRol systemRol)
        {
            try
            {
                Operations operations = new Operations();

                try
                {
                    dbLibrary.tc_SystemRol.Add(systemRol);
                    dbLibrary.SaveChanges();
                    operations.Result  = "OK";
                    operations.Message = "Registro creado";
                }
                catch (DbEntityValidationException e)
                {
                    regOperacion = new StringBuilder("No se logro crear el registro:-");
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        regOperacion.AppendFormat("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                                  eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            regOperacion.AppendFormat("- Property: \"{0}\", Error: \"{1}\"",
                                                      ve.PropertyName, ve.ErrorMessage);
                        }
                    }

                    operations.Result  = "Error";
                    operations.Message = regOperacion.ToString();
                }

                return(operations);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
 public AUTHOR CreateAuthor(AUTHOR author)
 {
     using (DbLibrary db = new DbLibrary())
     {
         try
         {
             db.AUTHORs.Add(author);
             db.SaveChanges();
             return(author);
         }
         catch
         {
             return(null);
         }
     }
 }
Esempio n. 4
0
 public bool EditAdmin(ADMIN eAdmin)
 {
     using (DbLibrary db = new DbLibrary())
     {
         try
         {
             db.Entry(db.ADMINS.FirstOrDefault(x => x.Username.Equals(eAdmin.Username))).CurrentValues.SetValues(eAdmin);
             db.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
 public AUTHOR EditAuthor(AUTHOR eauthor) //Returns the updated author and if failed returns null
 {
     using (DbLibrary db = new DbLibrary())
     {
         try
         {
             AUTHOR updatedAUTHOR = db.AUTHORs.Find(eauthor.Aid);
             db.Entry(updatedAUTHOR).CurrentValues.SetValues(eauthor);
             db.SaveChanges();
             return(updatedAUTHOR);
         }
         catch
         {
             return(null);
         }
     }
 }
 public bool CreateClassification(CLASSIFICATION eClassification)
 {
     using (DbLibrary db = new DbLibrary())
     {
         try
         {
             eClassification.SignId = GetNewID();
             db.CLASSIFICATIONs.Add(eClassification);
             db.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
 public bool EditClassification(CLASSIFICATION eClassification)
 {
     using (DbLibrary db = new DbLibrary())
     {
         try
         {
             CLASSIFICATION classification = db.CLASSIFICATIONs.FirstOrDefault(x => x.SignId.Equals(eClassification.SignId));
             db.Entry(classification).CurrentValues.SetValues(eClassification);
             db.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
 public bool DeleteAuthor(AUTHOR eauthor) //Returns true if amount of SaveChanges (int) is bigger than 1
 {
     using (DbLibrary db = new DbLibrary())
     {
         try
         {
             var author = db.AUTHORs.Include(a => a.BOOKs).FirstOrDefault(a => a.Aid.Equals(eauthor.Aid));
             author.BOOKs.Clear();
             db.AUTHORs.Remove(author);
             db.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Esempio n. 9
0
 public BOOK CreateBook(BOOK book)
 {
     using (DbLibrary db = new DbLibrary())
     {
         try
         {
             db.BOOKs.Add(book);
             db.ChangeTracker.Entries <AUTHOR>().ToList().ForEach(a => a.State         = EntityState.Unchanged);
             db.ChangeTracker.Entries <CLASSIFICATION>().ToList().ForEach(a => a.State = EntityState.Unchanged);
             db.SaveChanges();
             return(book);
         }
         catch
         {
             return(null);
         }
     }
 }
 public bool DeleteClassification(CLASSIFICATION eClassification)
 {
     using (DbLibrary db = new DbLibrary())
     {
         try
         {
             var classification = db.CLASSIFICATIONs.Include(a => a.BOOKs).FirstOrDefault(a => a.SignId == eClassification.SignId);
             classification.BOOKs.Clear();
             db.CLASSIFICATIONs.Remove(classification);
             db.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Esempio n. 11
0
 public bool DeleteBook(BOOK ebook)
 {
     using (DbLibrary db = new DbLibrary())
     {
         try
         {
             db.Configuration.LazyLoadingEnabled = false;
             var book = db.BOOKs.Include(a => a.AUTHORs).FirstOrDefault(a => a.ISBN == ebook.ISBN);
             book.AUTHORs.Clear();
             db.BOOKs.Remove(book);
             db.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Esempio n. 12
0
 public bool DeleteAdmin(string username)
 {
     using (DbLibrary db = new DbLibrary())
     {
         try
         {
             var admin = db.ADMINS.SingleOrDefault(x => x.Username.Equals(username));
             if (admin != null)
             {
                 db.ADMINS.Remove(admin);
                 db.SaveChanges();
                 return(true);
             }
             return(false);
         }
         catch
         {
             return(false);
         }
     }
 }