Example #1
0
        public List<ScholarshipBDO> GetAllScholarships()
        {
            List<Scholarship> sList = new List<Scholarship>();
            using (var DCEnt = new DCFIEntities())
            {
                var allScholarships = (DCEnt.Scholarships);
                sList = allScholarships.ToList<Scholarship>();
            }

            List<ScholarshipBDO> sBDOList = new List<ScholarshipBDO>();
            foreach (Scholarship s in sList)
            {
                ScholarshipBDO sBDO = new ScholarshipBDO();
                ConvertScholarshipToScholarshipBDO(s, sBDO);
                sBDOList.Add(sBDO);
            }
            return sBDOList;
        }
Example #2
0
        public Boolean CreateScholarship(ref ScholarshipBDO sBDO, ref string message)
        {
            message = "Scholarship Added Successfully";
            bool ret = true;

            Scholarship s = new Scholarship();
            ConvertScholarshipBDOToScholarship(sBDO, s);
            using (var DCEnt = new DCFIEntities())
            {
                DCEnt.Scholarships.Add(s);
                DCEnt.Entry(s).State = System.Data.Entity.EntityState.Added;
                int num = DCEnt.SaveChanges();
                sBDO.ScholarshipCode = s.ScholarshipCode;

                if (num != 1)
                {
                    ret = false;
                    message = "Adding of Scholarship failed";
                }
            }
            return ret;
        }
Example #3
0
 public void TranslateScholarshipToScholarshipBDO(Scholarship s, ScholarshipBDO sBDO) {
     sBDO.ScholarshipCode = s.ScholarshipCode;
     sBDO.Condition = s.Condition;
     sBDO.Deactivated = s.Deactivated;
     sBDO.Description = s.Description;
     sBDO.Privilege = s.Privilege;
 }
Example #4
0
        public Boolean UpdateScholarship(ref ScholarshipBDO sBDO, ref string message)
        {
            message = "Scholarship updated successfully.";
            Boolean ret = true;
            Scholarship sc = new Scholarship();
            ConvertScholarshipBDOToScholarship(sBDO, sc);
            Scholarship scholarshipInDB = new Scholarship();
            using (var DCEnt = new DCFIEntities())
            {
                var scholarshipCode = sBDO.ScholarshipCode;
                Scholarship sInDB = (from s in DCEnt.Scholarships
                                     where s.ScholarshipCode == scholarshipCode
                                     select s).FirstOrDefault();
                if (sInDB == null)
                {
                    throw new Exception("No Scholarship with ScholarshipCode " + sBDO.ScholarshipCode);
                }

                // 1st Part
                if (scholarshipInDB.ScholarshipDiscounts.Count == 0)
                {
                    foreach (ScholarshipDiscount sd in sc.ScholarshipDiscounts)
                    {
                        scholarshipInDB.ScholarshipDiscounts.Add(sd);
                    }
                }
                else if (scholarshipInDB.ScholarshipDiscounts.Count < sc.ScholarshipDiscounts.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<ScholarshipDiscount> sdToAdd = sc.ScholarshipDiscounts.Except(scholarshipInDB.ScholarshipDiscounts);
                    if (sdToAdd != null)
                    {
                        foreach (ScholarshipDiscount child in sdToAdd)
                        {
                            scholarshipInDB.ScholarshipDiscounts.Add(child);
                        }
                    }

                    IEnumerable<ScholarshipDiscount> sdToRemove = scholarshipInDB.ScholarshipDiscounts.Except(sc.ScholarshipDiscounts);
                    if (sdToRemove != null)
                    {
                        foreach (ScholarshipDiscount child in sdToRemove)
                        {
                            scholarshipInDB.ScholarshipDiscounts.Add(child);
                        }
                    }
                }
                else if (scholarshipInDB.ScholarshipDiscounts.Count > sc.ScholarshipDiscounts.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<ScholarshipDiscount> sdToAdd = sc.ScholarshipDiscounts.Except(scholarshipInDB.ScholarshipDiscounts);
                    if (sdToAdd != null)
                    {
                        foreach (ScholarshipDiscount child in sdToAdd)
                        {
                            scholarshipInDB.ScholarshipDiscounts.Add(child);
                        }
                    }

                    // TBC
                    IEnumerable<ScholarshipDiscount> sdToRemove = scholarshipInDB.ScholarshipDiscounts.Except(sc.ScholarshipDiscounts);
                    if (sdToRemove != null)
                    {
                        foreach (ScholarshipDiscount child in sdToRemove)
                        {
                            scholarshipInDB.ScholarshipDiscounts.Add(child);
                        }
                    }
                }
                else if (scholarshipInDB.ScholarshipDiscounts.Count == sc.ScholarshipDiscounts.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable<ScholarshipDiscount> sdToAdd = sc.ScholarshipDiscounts.Except(scholarshipInDB.ScholarshipDiscounts);
                    if (sdToAdd != null)
                    {
                        foreach (ScholarshipDiscount child in sdToAdd)
                        {
                            scholarshipInDB.ScholarshipDiscounts.Add(child);
                        }
                    }

                    IEnumerable<ScholarshipDiscount> sdToRemove = scholarshipInDB.ScholarshipDiscounts.Except(sc.ScholarshipDiscounts);
                    if (sdToRemove != null)
                    {
                        foreach (ScholarshipDiscount child in sdToRemove)
                        {
                            scholarshipInDB.ScholarshipDiscounts.Add(child);
                        }
                    }
                }
            }
            using (var DC = new DCFIEntities())
            {
                scholarshipInDB = sc;

                DC.Entry(scholarshipInDB).State = System.Data.Entity.EntityState.Modified;
                foreach (ScholarshipDiscount sd in scholarshipInDB.ScholarshipDiscounts)
                    DC.Entry(sd).State = sd.ScholarshipDiscountId == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;
                int number = DC.SaveChanges();

                if (number > 0)
                {
                    // ret = false;
                    message = "No Scholarship is updated.";
                }
            }

            return ret;

        }
Example #5
0
 private void ConvertScholarshipBDOToScholarship(ScholarshipBDO s, Scholarship sbdo)
 {
     sbdo.Condition = s.Condition;
     sbdo.Deactivated = s.Deactivated;
     sbdo.Description = s.Description;
     sbdo.Privilege = s.Privilege;
     sbdo.ScholarshipCode = s.ScholarshipCode;
 }
Example #6
0
 private void TranslateScholarshipBDOToScholarship(ScholarshipBDO sc, Scholarship sbdo)
 {
     sbdo.Condition = sc.Condition;
     sbdo.Deactivated = sc.Deactivated;
     sbdo.Description = sc.Description;
     sbdo.Privilege = sc.Privilege;
     sbdo.ScholarshipCode = sc.ScholarshipCode;
 }
Example #7
0
 // Done
 public bool UpdateScholarship(ref Scholarship scholarship, ref string message)
 {
     ScholarshipBDO sBDO = new ScholarshipBDO();
     TranslateScholarshipToScholarshipBDO(scholarship, sBDO);
     return sLogic.UpdateScholarship(ref sBDO, ref message);
 }
Example #8
0
 public bool CreateScholarship(ref Scholarship scholarship, ref string message)
 {
     ScholarshipBDO sbdo = new ScholarshipBDO();
     TranslateScholarshipToScholarshipBDO(scholarship, sbdo);
     return sLogic.CreateScholarship(ref sbdo, ref message);
 }
Example #9
0
 public Boolean UpdateScholarship(ref ScholarshipBDO sbdo, ref string message)
 {
     return sDAO.UpdateScholarship(ref sbdo, ref message);
 }