Ejemplo n.º 1
0
        public string GetGridData(GridSettings grid)
        {
            try
            {
                using (var ctx = new CRUDSampleEntities())
                {
                    var query = ctx.tblCatalogs.AsQueryable();


                    int count;
                    var data = query.GridCommonSettings(grid, out count);

                    var result = new
                    {
                        total   = (int)Math.Ceiling((double)count / grid.PageSize),
                        page    = grid.PageIndex,
                        records = count,
                        rows    = (from c in data
                                   select new
                        {
                            Id = c.Id,
                            CatalogName = c.CatalogName,
                            Barcode = c.Barcode,
                            TypeId = c.TypeId,
                            TypeName = c.tblCatalogType.TypeName,
                        }).ToArray()
                    };
                    return(JsonConvert.SerializeObject(result, new IsoDateTimeConverter()));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 2
0
 public tblCatalog GetById(int id)
 {
     try
     {
         using (var ctx = new CRUDSampleEntities())
         {
             return(ctx.tblCatalogs.Where(c => c.Id == id).FirstOrDefault());
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 3
0
 public bool IsCatalogExist(string catalogName, string barcode)
 {
     try
     {
         using (var ctx = new CRUDSampleEntities())
         {
             return(ctx.tblCatalogs.Where(t => t.CatalogName == catalogName && t.Barcode == barcode).Count() > 0 ? true : false);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 4
0
 public bool IsFirstNameExist(string firstname, int StudentId)
 {
     try
     {
         using (var ctx = new CRUDSampleEntities())
         {
             return(ctx.tblStudents.Where(t => t.FirstName == firstname && t.StudentId != StudentId).Count() > 0 ? true : false);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 5
0
 public tblStudent GetById(int id)
 {
     try
     {
         using (var ctx = new CRUDSampleEntities())
         {
             return(ctx.tblStudents.Include(c => c.tblContactDetail).Where(c => c.StudentId == id).FirstOrDefault());
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 6
0
 public List <tblCatalogType> GetAllCatalogTypes()
 {
     try
     {
         using (var ctx = new CRUDSampleEntities())
         {
             return(ctx.tblCatalogTypes.ToList());
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 7
0
 public void Create(tblCatalog oCatalog)
 {
     try
     {
         using (var ctx = new CRUDSampleEntities())
         {
             ctx.tblCatalogs.Add(oCatalog);
             ctx.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 8
0
 public void Update(tblCatalog oCatalog)
 {
     try
     {
         using (var ctx = new CRUDSampleEntities())
         {
             ctx.Entry(oCatalog).State = EntityState.Modified;
             ctx.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 9
0
 public void Delete(int id)
 {
     try
     {
         using (var ctx = new CRUDSampleEntities())
         {
             tblCatalog oCatalog = ctx.tblCatalogs.Where(c => c.Id == id).FirstOrDefault();
             ctx.tblCatalogs.Remove(oCatalog);
             ctx.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 10
0
 public void Delete(int id)
 {
     try
     {
         using (var ctx = new CRUDSampleEntities())
         {
             tblStudent oStudent = ctx.tblStudents.Where(c => c.StudentId == id).FirstOrDefault();
             ctx.tblStudents.Remove(oStudent);
             ctx.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 11
0
        public void Create(tblStudent oStudent)
        {
            try
            {
                using (var ctx = new CRUDSampleEntities())
                {
                    oStudent.ModifiedDate = DateTime.Now;

                    oStudent.CreateDate   = DateTime.Now;
                    oStudent.ModifiedDate = DateTime.Now;
                    ctx.tblStudents.Add(oStudent);

                    ctx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 12
0
        public void Update(tblStudent oStudent)
        {
            try
            {
                using (var ctx = new CRUDSampleEntities())
                {
                    ctx.tblContactDetails.Attach(oStudent.tblContactDetail);
                    ctx.Entry(oStudent.tblContactDetail).State = EntityState.Modified;

                    ctx.tblStudents.Attach(oStudent);
                    ctx.Entry(oStudent).State = EntityState.Modified;

                    ctx.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 13
0
        public string GetGridData(GridSettings grid)
        {
            try
            {
                using (var ctx = new CRUDSampleEntities())
                {
                    var query = ctx.tblStudents.AsQueryable();


                    int count;
                    var data = query.GridCommonSettings(grid, out count);

                    var result = new
                    {
                        total   = (int)Math.Ceiling((double)count / grid.PageSize),
                        page    = grid.PageIndex,
                        records = count,
                        rows    = (from c in data
                                   select new
                        {
                            StudentId = c.StudentId,
                            FirstName = c.FirstName,
                            MiddleName = c.MiddleName,
                            LastName = c.LastName,
                            ContactId = c.ContactId,
                            CreateDate = c.CreateDate,
                            ModifiedDate = c.ModifiedDate,
                            ContactDetail = c.tblContactDetail.ContactDetail
                        }).ToArray()
                    };
                    return(JsonConvert.SerializeObject(result, new IsoDateTimeConverter()));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }