public SubjectBDO GetSubject(string subjectCode) { SubjectBDO sbdo = new SubjectBDO(); Subject subj = new Subject(); try { using (var DCEnt = new DCFIEntities()) { var sub = (from s in DCEnt.Subjects where s.SubjectCode == subjectCode select s).FirstOrDefault(); subj = sub; ConvertSubjectToSubjectBDO(subj, sbdo); } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } return sbdo; }
public void ConvertSubjectBDOToSubject(SubjectBDO sbdo, Subject s) { s.SubjectID = sbdo.SubjectID; s.Description = sbdo.Description; s.GradeLevel = sbdo.GradeLevel; s.LearningAreaCode = sbdo.LearningAreaCode; s.SubjectCode = sbdo.SubjectCode; }
public void ConvertSubjectToSubjectBDO(Subject s, SubjectBDO sbdo) { sbdo.Description = s.Description; sbdo.GradeLevel = s.GradeLevel; sbdo.LearningAreaCode = s.LearningAreaCode; sbdo.SubjectCode = s.SubjectCode; sbdo.SubjectID = s.SubjectID; sbdo.MPW = s.MPW; }
public void ConvertSubjectToSubjectBDO(Subject s, SubjectBDO sbdo) { LearningAreaDAO ldao = new LearningAreaDAO(); LearningAreaBDO la = new LearningAreaBDO(); sbdo.Description = s.Description; sbdo.GradeLevel = s.GradeLevel; sbdo.LearningAreaCode = s.LearningAreaCode; sbdo.SubjectCode = s.SubjectCode; sbdo.SubjectID = s.SubjectID; // ldao.ConvertLearningAreaToLearningAreaBDO(s.LearningArea, la); sbdo.LearningArea = la; }
public void ConvertSubjectBDOToSubject(SubjectBDO sbdo, Subject s) { //LearningAreaDAO ldao = new LearningAreaDAO(); //LearningArea l = new LearningArea();//s.LearningArea = sbdo.LearningArea; s.SubjectID = sbdo.SubjectID; s.Description = sbdo.Description; s.GradeLevel = sbdo.GradeLevel; s.LearningAreaCode = sbdo.LearningAreaCode; s.SubjectCode = sbdo.SubjectCode; s.MPW = sbdo.MPW; // ldao.ConvertLearningAreaBDOToLearningArea(sbdo.LearningArea, l); // s.LearningArea = l; }
public SubjectBDO GetSubject(string subjectCode) { SubjectBDO sbdo = new SubjectBDO(); Subject subj = new Subject(); using (var DCEnt = new DCFIEntities()) { var sub = (from s in DCEnt.Subjects where s.SubjectCode == subjectCode select s).FirstOrDefault(); subj = sub; } ConvertSubjectToSubjectBDO(subj, sbdo); return sbdo; }
public Boolean CreateSubject(ref SubjectBDO subjectBDO, ref string message) { message = "Subject Added Successfully"; bool ret = true; Subject s = new Subject(); ConvertSubjectBDOToSubject(subjectBDO, s); using (var DCEnt = new DCFIEntities()) { DCEnt.Subjects.Attach(s); DCEnt.Entry(s).State = System.Data.Entity.EntityState.Added; int num = DCEnt.SaveChanges(); if (num != 1) { ret = false; message = "Adding of Subject failed"; } } return ret; }
public Boolean CreateSubject(ref SubjectBDO subjectBDO, ref string message) { message = "Subject Added Successfully"; bool ret = true; Subject s = new Subject(); try { ConvertSubjectBDOToSubject(subjectBDO, s); using (var DCEnt = new DCFIEntities()) { DCEnt.Subjects.Attach(s); DCEnt.Entry(s).State = System.Data.Entity.EntityState.Added; int num = DCEnt.SaveChanges(); if (num != 1) { ret = false; message = "Adding of Subject failed"; } } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } return ret; }
public List<Subject> ToSubjectList(List<SubjectBDO> slist) { List<Subject> sList = new List<Subject>(); foreach (SubjectBDO sbdo in slist) { Subject s = new Subject(); ConvertSubjectBDOToSubject(sbdo, s); sList.Add(s); } return sList; }
public ICollection<Subject> ToSubjectList(List<SubjectBDO> slist) { SubjectDAO sd = new SubjectDAO(); ICollection<Subject> subjectList = new List<Subject>(); foreach (SubjectBDO sbdo in slist) { Subject subject = new Subject(); sd.ConvertSubjectBDOToSubject(sbdo, subject); subjectList.Add(subject); } return subjectList; //SubjectDAO sd = new SubjectDAO(); //ICollection<Subject> sList = new List<Subject>(); //foreach (SubjectBDO sbdo in slist) //{ // Subject s = new Subject(); // sd.ConvertSubjectToSubjectBDO(s, sbdo); // sList.Add(s); //} //return sList; }
public ICollection<Subject> ToSubjectList(List<SubjectBDO> slist) { SubjectDAO sd = new SubjectDAO(); ICollection<Subject> subjectList = new List<Subject>(); foreach (SubjectBDO sbdo in slist) { Subject subject = new Subject(); sd.ConvertSubjectBDOToSubject(sbdo, subject); subjectList.Add(subject); } return subjectList; }
private Boolean CompareSubject(Subject inDB, Subject inNew) { if (inDB.LearningAreaCode == inNew.LearningAreaCode && inDB.SubjectCode == inNew.SubjectCode && inDB.Description == inNew.Description && inDB.MPW == inNew.MPW) return true; else return false; }
public Boolean UpdateLearningArea(ref LearningAreaBDO laBDO, ref string message) { List<Subject> toRemove; List<Subject> toAdd; List<Subject> toUpdate; Boolean ret = true; LearningArea l = new LearningArea(); LearningArea laInDB = new LearningArea(); LearningArea laInDB2 = new LearningArea(); try { using (var DCEnt = new DCFIEntities()) { var learningAreaCode = laBDO.LearningAreaCode; laInDB = (from la in DCEnt.LearningAreas where la.LearningAreaCode.Equals(learningAreaCode) select la).FirstOrDefault(); if (laInDB == null) { throw new Exception("No Learning Area with Code " + laBDO.LearningAreaCode); } l.Academic = laBDO.Academic; l.Description = laBDO.Description; l.LearningAreaCode = laBDO.LearningAreaCode; l.RatePerSubject = laBDO.RatePerSubject; l.RatePerUnit = laBDO.RatePerUnit; l.Units = laBDO.Units; l.Subjects = ToSubjectList(laBDO.Subjects); if (laInDB.Subjects.Count == 0) { foreach (Subject s in l.Subjects) { laInDB.Subjects.Add(s); } } else { toRemove = new List<Subject>(); toAdd = new List<Subject>(); toUpdate = new List<Subject>(); foreach (Subject s in l.Subjects) { Subject subj = new Subject(); subj = laInDB.Subjects.Where(sub => sub.SubjectCode == s.SubjectCode).FirstOrDefault(); if (subj == null) { DCEnt.Subjects.Add(s); DCEnt.Entry(s).State = System.Data.Entity.EntityState.Added; } else { if (!CompareSubject(subj, s)) { toUpdate.Add(s); } } } //Add new Subject if (toAdd.Count > 0) { foreach (Subject c in toAdd) { DCEnt.Subjects.Add(c); DCEnt.Entry(c).State = System.Data.Entity.EntityState.Added; } } foreach (Subject c in laInDB.Subjects) { Subject subj = new Subject(); subj = l.Subjects.Where(sub => sub.SubjectCode == c.SubjectCode).FirstOrDefault(); Subject upSubj = new Subject(); upSubj = toUpdate.Where(sub => sub.SubjectCode == c.SubjectCode).FirstOrDefault(); //toRemove subject if (subj == null) { DCEnt.Subjects.Remove(c); DCEnt.Entry(c).State = System.Data.Entity.EntityState.Deleted; } //toUpdate subject if (upSubj != null) { c.Description = upSubj.Description; c.MPW = upSubj.MPW; DCEnt.Entry(c).State = System.Data.Entity.EntityState.Modified; } } DCEnt.LearningAreas.Attach(laInDB); DCEnt.Entry(laInDB).State = System.Data.Entity.EntityState.Modified; } int num = DCEnt.SaveChanges(); if (num > 0) { message = "No learning area is updated."; } } } catch (DbEntityValidationException dbEx) { foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } return ret; }