Exemplo n.º 1
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;
 }
Exemplo n.º 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;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 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;

        }
Exemplo n.º 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;
 }
Exemplo n.º 6
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);
        }