public void save(StudentBillingCycle StudentBillingCycle, string userId, bool isNew) { try { using (var context = new SmsMisDB()) { var entry = context.Entry(StudentBillingCycle); if (entry != null) { if (isNew) { entry.State = System.Data.Entity.EntityState.Added; } else { entry.State = System.Data.Entity.EntityState.Modified; } context.SaveChanges(); } } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { } catch (Exception ex) { } }
public ContentResult deleteStudentBillingCycle(StudentBillingCycle StudentBillingCycle) { try { new hdlStudentBillingCycle().delete(StudentBillingCycle); } catch (Exception ex) { Response.StatusCode = 500; Content(JsonConvert.SerializeObject(new { error = ex.Message })); } return(getAllStudentBillingCycle(StudentBillingCycle.CompanyCode)); }
public ContentResult saveStudentBillingCycle(StudentBillingCycle StudentBillingCycle, bool isNew) { try { new hdlStudentBillingCycle().save(StudentBillingCycle, Convert.ToString(Session["User"]), isNew); } catch (Exception ex) { Response.StatusCode = 500; Content(JsonConvert.SerializeObject(new { error = ex.Message })); } return(getAllStudentBillingCycle(StudentBillingCycle.CompanyCode)); }
public void delete(StudentBillingCycle StudentBillingCycle) { try { var context = new SmsMisDB(); context.StudentBillingCycle.Attach(StudentBillingCycle); var entry = context.Entry(StudentBillingCycle); if (entry != null) { entry.State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { //throw SmsMis.Models.Console.Common.ExceptionTranslater.translate(ex); throw ex; } catch (Exception ex) { //throw SmsMis.Models.Console.Common.ExceptionTranslater.translate(ex); throw ex; } }
public void save(Student Student, string imgFile, string path) { try { using (var context = new SmsMisDB()) { Student.AddDateTime = DateTime.Now; bool isNew = true; var entry = context.Entry(Student); if (entry != null) { if (!string.IsNullOrEmpty(imgFile)) { Student.LogoPath = "../upload/students/"; } if (Student.StudentNo == 0) { Student.StudentNo = Functions.getNextPk("Student", Student.StudentNo, Student.CompanyCode, Student.BranchCode, Student.SessionCode); entry.State = System.Data.Entity.EntityState.Added; } else { isNew = false; if (Student.StudentApplicationCheckList != null && Student.StudentApplicationCheckList.Count > 0) { Student.StudentApplicationCheckList.ToList().ForEach(i => { i.StudentNo = Student.StudentNo; }); } if (Student.StudentMarketingReference != null && Student.StudentMarketingReference.Count > 0) { Student.StudentMarketingReference.ToList().ForEach(i => { i.StudentNo = Student.StudentNo; }); } if (Student.StudentLastClassSubject != null && Student.StudentLastClassSubject.Count > 0) { Student.StudentLastClassSubject.ToList().ForEach(i => { i.StudentNo = Student.StudentNo; }); } if (Student.StudentKinship != null && Student.StudentKinship.Count > 0) { Student.StudentKinship.ToList().ForEach(i => { i.StudentNo = Student.StudentNo; }); } if (Student.StudentSubjectList != null && Student.StudentSubjectList.Count > 0) { Student.StudentSubjectList.ToList().ForEach(i => { i.StudentNo = Student.StudentNo; }); } if (Student.StudentMarketingReference != null && Student.StudentMarketingReference.Count > 0) { Student.StudentMarketingReference.ToList <StudentMarketingReference>().ForEach(s => context.Entry(s).State = System.Data.Entity.EntityState.Added); } if (Student.StudentLastClassSubject != null && Student.StudentLastClassSubject.Count > 0) { Student.StudentLastClassSubject.ToList <StudentLastClassSubject>().ForEach(s => context.Entry(s).State = System.Data.Entity.EntityState.Added); } if (Student.StudentKinship != null && Student.StudentKinship.Count > 0) { Student.StudentKinship.ToList <StudentKinship>().ForEach(s => context.Entry(s).State = System.Data.Entity.EntityState.Added); } if (Student.StudentApplicationCheckList != null && Student.StudentApplicationCheckList.Count > 0) { Student.StudentApplicationCheckList.ToList <StudentApplicationCheckList>().ForEach(s => context.Entry(s).State = System.Data.Entity.EntityState.Added); } if (Student.StudentSubjectList != null && Student.StudentSubjectList.Count > 0) { Student.StudentSubjectList.ToList <StudentSubject>().ForEach(s => context.Entry(s).State = System.Data.Entity.EntityState.Added); } entry.State = System.Data.Entity.EntityState.Modified; } context.StudentApplicationCheckList.ToList().Where(i => i.CompanyCode == Student.CompanyCode && i.BranchCode == Student.BranchCode && i.SessionCode == Student.SessionCode && i.StudentNo == Student.StudentNo).ToList <StudentApplicationCheckList>().ForEach(s => context.Entry(s).State = System.Data.Entity.EntityState.Deleted); context.StudentMarketingReference.ToList().Where(i => i.CompanyCode == Student.CompanyCode && i.BranchCode == Student.BranchCode && i.SessionCode == Student.SessionCode && i.StudentNo == Student.StudentNo).ToList <StudentMarketingReference>().ForEach(s => context.Entry(s).State = System.Data.Entity.EntityState.Deleted); context.StudentLastClassSubject.ToList().Where(i => i.CompanyCode == Student.CompanyCode && i.BranchCode == Student.BranchCode && i.SessionCode == Student.SessionCode && i.StudentNo == Student.StudentNo).ToList <StudentLastClassSubject>().ForEach(s => context.Entry(s).State = System.Data.Entity.EntityState.Deleted); context.StudentKinship.ToList().Where(i => i.CompanyCode == Student.CompanyCode && i.BranchCode == Student.BranchCode && i.SessionCode == Student.SessionCode && i.StudentNo == Student.StudentNo).ToList <StudentKinship>().ForEach(s => context.Entry(s).State = System.Data.Entity.EntityState.Deleted); context.StudentSubject.ToList().Where(i => i.CompanyCode == Student.CompanyCode && i.BranchCode == Student.BranchCode && i.SessionCode == Student.SessionCode && i.StudentNo == Student.StudentNo).ToList <StudentSubject>().ForEach(s => context.Entry(s).State = System.Data.Entity.EntityState.Deleted); context.SaveChanges(); int studentNo = Student.StudentNo; try { if (isNew) { Prefrences p = context.Prefrences.Where(a => a.CompanyCode == Student.CompanyCode && a.BranchCode == Student.BranchCode).FirstOrDefault(); if (p != null && p.StudentBillingCycle > 0) { StudentBillingCycle sbc = new StudentBillingCycle(); sbc.BiilingCycle = p.StudentBillingCycle; sbc.BranchCode = Student.BranchCode; sbc.CompanyCode = Student.CompanyCode; sbc.SessionCode = Student.SessionCode; sbc.StudentNo = Student.StudentNo; new SmsMis.Models.Console.Handlers.Fee.hdlStudentBillingCycle().save(sbc, Student.AddByUserId, true); } } } catch (Exception) { } try { char[] split = { ',' }; string base64Image = imgFile.Split(split)[1];// data:image/jpeg;base64, byte[] imageBytes = Convert.FromBase64String(base64Image); MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length); ms.Write(imageBytes, 0, imageBytes.Length); Image image = Image.FromStream(ms, true); image.Save(path + Student.CompanyCode + "_" + Student.BranchCode + "_" + Student.SessionCode + "_" + Student.StudentNo + ".png"); } catch (Exception ex) { } } //List<object> parameters = new List<object>(); //string strQuery = string.Format("Exec SpSaveVoucher {0},{1},{2},{3},{4},{5},{6}", Student.CompanyCode, Student.BranchCode, Student.AddByUserId, Student.Amount, Student.StudentNo, (Student.VoucherCode == null ? 0 : Student.VoucherCode), (Student.VoucherNo == null ? 0 : Student.VoucherNo)); //context.Database.ExecuteSqlCommand(strQuery); } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { throw ex; } catch (Exception ex) { throw ex; } }