public Boolean CreateCurriculum(ref CurriculumBDO cbdo, ref string message) { message = "Curriculum Added Successfully"; bool ret = true; Curriculum cur = new Curriculum(); try { ConvertCurriculumBDOToCurriculum(cbdo, cur); using (var DCEnt = new DCFIEntities()) { DCEnt.Curriculums.Add(cur); DCEnt.Entry(cur).State = System.Data.Entity.EntityState.Added; int num = DCEnt.SaveChanges(); if (num == 0) { ret = false; message = "Adding of Curriculum 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; }
private void ConvertCurriculumToCurriculumBDO(Curriculum c, CurriculumBDO currBDO) { currBDO.CurrentCurr = c.CurrentCurr; currBDO.CurriculumCode = c.CurriculumCode; currBDO.CurriculumSubjects = GetCurriculumSubjects(c.CurriculumCode); currBDO.Description = c.Description; }
public List<CurriculumBDO> GetAllCurriculums() { List<Curriculum> currList = new List<Curriculum>(); List<CurriculumBDO> currBDOList = new List<CurriculumBDO>(); try { using (var DCEnt = new DCFIEntities()) { var allCurr = (DCEnt.Curriculums); currList = allCurr.ToList<Curriculum>(); foreach (Curriculum c in currList) { CurriculumBDO currBDO = new CurriculumBDO(); ConvertCurriculumToCurriculumBDO(c, currBDO); currBDOList.Add(currBDO); } } } 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 currBDOList; }
private void ConvertCurriculumBDOToCurriculum(CurriculumBDO c, Curriculum currBDO) { currBDO.CurrentCurr = c.CurrentCurr; currBDO.CurriculumCode = c.CurriculumCode; currBDO.CurriculumSubjects = ToCurriculumSubjectList(c.CurriculumSubjects); currBDO.Description = c.Description; }
public Boolean UpdateCurriculum(ref CurriculumBDO cbdo, ref string message) { message = "Curriculum updated successfully."; Boolean ret = true; Curriculum c = new Curriculum(); ConvertCurriculumBDOToCurriculum(cbdo, c); using (var DCEnt = new DCFIEntities()) { var cCode = c.CurriculumCode; Curriculum cInDB = (from curri in DCEnt.Curriculums where curri.CurriculumCode == cCode select curri).FirstOrDefault(); if (cInDB == null) { throw new Exception("No Curriculum with Code" + c.CurriculumCode); } DCEnt.Curriculums.Remove(cInDB); ConvertCurriculumBDOToCurriculum(cbdo, cInDB); DCEnt.Curriculums.Attach(cInDB); DCEnt.Entry(cInDB).State = System.Data.Entity.EntityState.Modified; int num = DCEnt.SaveChanges(); if (num == 0) { ret = false; message = "No Curriculum is updated."; } } return ret; }
public List<CurriculumBDO> GetAllCurriculums() { List<Curriculum> currList = new List<Curriculum>(); using (var DCEnt = new DCFIEntities()) { var allCurr = (DCEnt.Curriculums); currList = allCurr.ToList<Curriculum>(); } List<CurriculumBDO> currBDOList = new List<CurriculumBDO>(); foreach (Curriculum c in currList) { CurriculumBDO currBDO = new CurriculumBDO(); ConvertCurriculumToCurriculumBDO(c, currBDO); currBDOList.Add(currBDO); } return currBDOList; }
public Boolean CreateCurriculum(ref CurriculumBDO cbdo, ref string message) { message = "Curriculum Added Successfully"; bool ret = true; Curriculum cur = new Curriculum(); ConvertCurriculumBDOToCurriculum(cbdo, cur); using (var DCEnt = new DCFIEntities()) { DCEnt.Curriculums.Add(cur); DCEnt.Entry(cur).State = System.Data.Entity.EntityState.Added; int num = DCEnt.SaveChanges(); if (num == 0) { ret = false; message = "Adding of Curriculum failed"; } } return ret; }
public bool CreateCurriculum(ref Curriculum curriculum, ref string message) { CurriculumBDO cbdo = new CurriculumBDO(); TranslateCurriculumToCurriculumBDO(curriculum, cbdo); return clogic.CreateCurriculum(ref cbdo, ref message); }
private void TranslateCurriculumBDOToCurriculum(CurriculumBDO curriculum, Curriculum cbdo) { cbdo.CurrentCurr = curriculum.CurrentCurr; cbdo.CurriculumCode = curriculum.CurriculumCode; cbdo.Description = curriculum.Description; cbdo.CurriculumSubjects = ToCurriculumSubjectList(curriculum.CurriculumSubjects); }
private void TranslateCurriculumToCurriculumBDO(Curriculum curriculum, CurriculumBDO cbdo) { cbdo.CurrentCurr = curriculum.CurrentCurr; cbdo.CurriculumCode = curriculum.CurriculumCode; cbdo.Description = curriculum.Description; cbdo.CurriculumSubjects = ToCurriculumSubjectBDOList(curriculum.CurriculumSubjects.ToList<CurriculumSubject>()); }
public bool UpdateCurriculum(ref Curriculum curriculum, ref string message) { CurriculumBDO cb = new CurriculumBDO(); TranslateCurriculumToCurriculumBDO(curriculum, cb); return clogic.UpdateCurriculum(ref cb, ref message); }
public Boolean UpdateCurriculum(ref CurriculumBDO cbdo, ref string message) { message = "Curriculum updated successfully."; List<CurriculumSubject> toRemove; List<CurriculumSubject> toAdd; Boolean ret = true; Curriculum c = new Curriculum(); Curriculum cInDB = new Curriculum(); try { ConvertCurriculumBDOToCurriculum(cbdo, c); using (var DCEnt = new DCFIEntities()) { var cCode = c.CurriculumCode; cInDB = (from curri in DCEnt.Curriculums where curri.CurriculumCode == cCode select curri).FirstOrDefault(); if (cInDB == null) { throw new Exception("No Curriculum with Code" + c.CurriculumCode); } if (cInDB.CurriculumSubjects.Count == 0) { foreach (CurriculumSubject s in c.CurriculumSubjects) cInDB.CurriculumSubjects.Add(s); } else { toRemove = new List<CurriculumSubject>(); toAdd = new List<CurriculumSubject>(); if (cInDB.CurriculumSubjects.Count < c.CurriculumSubjects.Count) { foreach (CurriculumSubject cs in c.CurriculumSubjects) { int co = cInDB.CurriculumSubjects.Where(sub => sub.CurrSubCode == cs.CurrSubCode).Count(); if (co == 0) toAdd.Add(cs); } foreach (CurriculumSubject cs in cInDB.CurriculumSubjects) { int co = c.CurriculumSubjects.Where(sub => sub.CurrSubCode == cs.CurrSubCode).Count(); if (co == 0) toRemove.Add(cs); } } else if (cInDB.CurriculumSubjects.Count > c.CurriculumSubjects.Count) { foreach (CurriculumSubject cs in c.CurriculumSubjects) {//check here if correct logic int co = cInDB.CurriculumSubjects.Where(sub => sub.CurrSubCode == cs.CurrSubCode).Count(); if (co == 0) toAdd.Add(cs); } foreach (CurriculumSubject cs in cInDB.CurriculumSubjects) { int co = c.CurriculumSubjects.Where(sub => sub.CurrSubCode == cs.CurrSubCode).Count(); if (co == 0) toRemove.Add(cs); } } else if (cInDB.CurriculumSubjects.Count == c.CurriculumSubjects.Count) { foreach (CurriculumSubject s in c.CurriculumSubjects) { int co = cInDB.CurriculumSubjects.Where(sub => sub.CurrSubCode == s.CurrSubCode).Count(); if (co == 0) toAdd.Add(s); } foreach (CurriculumSubject cs in cInDB.CurriculumSubjects) { int co = c.CurriculumSubjects.Where(sub => sub.CurrSubCode == cs.CurrSubCode).Count(); if (co == 0) toRemove.Add(cs); } } foreach (CurriculumSubject cs in toAdd) { cInDB.CurriculumSubjects.Add(cs); } foreach (CurriculumSubject cs in toRemove) { DCEnt.CurriculumSubjects.Remove(cs); DCEnt.Entry(cs).State = System.Data.Entity.EntityState.Deleted; } } if (CompareCurrs(cInDB, c)) { foreach (CurriculumSubject cs in cInDB.CurriculumSubjects) DCEnt.Entry(cs).State = cs.CurriculumSubjectsID == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified; DCEnt.SaveChanges(); } else { //DCEnt.Curriculums.Remove(cInDB); cInDB.CurrentCurr = c.CurrentCurr; cInDB.CurriculumCode = c.CurriculumCode; // cInDB.CurriculumSubjects = c.CurriculumSubjects; cInDB.Description = c.Description; DCEnt.Curriculums.Attach(cInDB); DCEnt.Entry(cInDB).State = System.Data.Entity.EntityState.Modified; DCEnt.SaveChanges(); } } } 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 Boolean UpdateCurriculum(ref CurriculumBDO cbdo, ref string message) { return cdao.UpdateCurriculum(ref cbdo, ref message); }