Пример #1
0
        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;
        }
Пример #2
0
 private void ConvertCurriculumToCurriculumBDO(Curriculum c, CurriculumBDO currBDO)
 {
     currBDO.CurrentCurr = c.CurrentCurr;
     currBDO.CurriculumCode = c.CurriculumCode;
     currBDO.CurriculumSubjects = GetCurriculumSubjects(c.CurriculumCode);
     currBDO.Description = c.Description;
 }
Пример #3
0
        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;
        }
Пример #4
0
 private void ConvertCurriculumBDOToCurriculum(CurriculumBDO c, Curriculum currBDO)
 {
     currBDO.CurrentCurr = c.CurrentCurr;
     currBDO.CurriculumCode = c.CurriculumCode;
     currBDO.CurriculumSubjects = ToCurriculumSubjectList(c.CurriculumSubjects);
     currBDO.Description = c.Description;
 }
Пример #5
0
        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;
        }
Пример #6
0
        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;
        }
Пример #7
0
        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;
        }
Пример #8
0
 public bool CreateCurriculum(ref Curriculum curriculum, ref string message)
 {
     CurriculumBDO cbdo = new CurriculumBDO();
     TranslateCurriculumToCurriculumBDO(curriculum, cbdo);
     return clogic.CreateCurriculum(ref cbdo, ref message);
 }
Пример #9
0
        private void TranslateCurriculumBDOToCurriculum(CurriculumBDO curriculum, Curriculum cbdo)
        {
            cbdo.CurrentCurr = curriculum.CurrentCurr;
            cbdo.CurriculumCode = curriculum.CurriculumCode;
            cbdo.Description = curriculum.Description;
            cbdo.CurriculumSubjects = ToCurriculumSubjectList(curriculum.CurriculumSubjects);

        }
Пример #10
0
        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>());

        }
Пример #11
0
 public bool UpdateCurriculum(ref Curriculum curriculum, ref string message)
 {
     CurriculumBDO cb = new CurriculumBDO();
     TranslateCurriculumToCurriculumBDO(curriculum, cb);
     return clogic.UpdateCurriculum(ref cb, ref message);
 }
Пример #12
0
        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;
        }
Пример #13
0
 public Boolean UpdateCurriculum(ref CurriculumBDO cbdo, ref string message)
 {
     return cdao.UpdateCurriculum(ref cbdo, ref message);
 }