Ejemplo n.º 1
0
 protected void Refresh()
 {
     if (dbEntities != null)
     {
         dbEntities.Dispose();
     }
     dbEntities = LibraryEntities.Instance();
 }
Ejemplo n.º 2
0
        public override object Add(object Obj)
        {
            student student = (student)Obj;

            if (student.id == null)
            {
                student.id = StringUtil.GenerateRandomNumber(7);
            }
            student newstudent = dbEntities.students.Add(student);

            try
            {
                dbEntities.SaveChanges();
                return(newstudent);
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string message = string.Format("{0}:{1}",
                                                       validationErrors.Entry.Entity.ToString(),
                                                       validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }
                throw raise;
                //  return null;
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException dbEx)
            {
                Exception raise = new Exception(dbEx.StackTrace);
                dbEntities.Dispose();
                dbEntities = LibraryEntities.Instance();
                return(null);

                throw raise;
                //  return null;
            }
        }
Ejemplo n.º 3
0
        public override object Add(object Obj)
        {
            using (LibraryEntities ctx = LibraryEntities.Instance())
            {
                visit visit   = (visit)Obj;
                visit DBVisit = null;
                try
                {
                    DBVisit = ctx.visits.Add(visit);
                    int RES = ctx.SaveChanges();
                }

                catch (Exception e)
                {
                    DBVisit = null;
                }
                return(DBVisit);
            }
        }
Ejemplo n.º 4
0
        public student GetByIdFull(string Id)
        {
            dbEntities = LibraryEntities.Instance();

            try
            {
                student student = (from s in dbEntities.students where s.id.Equals(Id) select s).SingleOrDefault();
                if (student != null)
                {
                    student.@class = (from c in dbEntities.classes where c.id.Equals(student.class_id) select c).SingleOrDefault();
                }
                return(student);
            }
            catch (InvalidOperationException ex)
            {
                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }