コード例 #1
0
 public static void SaveFamily(dtoFamily family)
 {
     DAL.Family NewFamily   = DTO.dtoFamily.castToDal(family);
     DAL.Family ExistFamily = context.Families.FirstOrDefault(p => p.FamilyId == NewFamily.FamilyId);
     if (ExistFamily != null)
     {
         context.Families.Remove(ExistFamily);
         context.SaveChanges();
     }
     context.Families.Add(NewFamily);
     context.SaveChanges();
 }
コード例 #2
0
        public static void DeleteChildrenWithDetails(string childId)
        {
            Child ExistChild = new Child();

            ExistChild = context.Childs.FirstOrDefault(p => p.IdentityNum == childId);
            if (ExistChild != null)
            {
                int family  = context.Childs.Count(p => p.FamilyId == ExistChild.FamilyId);
                var lessons = context.Lessons.Where(p => p.ChildId == childId);
                foreach (var item in lessons)
                {
                    item.ChildId = childId;
                    //context.SaveChanges();

                    //context.SaveChanges();
                    //Lesson lesson = item;
                    context.Lessons.Remove(item);
                }
                context.SaveChanges();
                var groups = context.Groups.Where(p => p.Childs.FirstOrDefault(q => q.IdentityNum == childId) != null);

                foreach (var item in groups)
                {
                    item.Childs.ToList().RemoveAll(r => r.IdentityNum == childId);

                    //foreach (var it in item.Childs)
                    //{

                    //    if (it.IdentityNum == childId)
                    //        it.IdentityNum = null;
                    //}
                }
                context.SaveChanges();

                context.Childs.Remove(ExistChild);
                context.SaveChanges();
                if (family == 1)
                {
                    DAL.Family family1 = context.Families.FirstOrDefault(p => p.FamilyId == ExistChild.FamilyId);
                    context.Families.Remove(family1);
                    context.SaveChanges();
                }
            }
        }
コード例 #3
0
 public static DTO.ChildWithFamilyDetails GetChildWithDetailsById(string childId)
 {
     DAL.Child  child  = new DAL.Child();
     DAL.Family family = new DAL.Family();
     DAL.City   city   = new DAL.City();
     DAL.School school = new DAL.School();
     child  = context.Childs.FirstOrDefault(p => p.IdentityNum == childId);
     family = context.Families.FirstOrDefault(p => p.FamilyId == child.FamilyId);
     school = context.Schools.FirstOrDefault(p => p.SchoolId == child.SchoolId);
     city   = context.Cities.FirstOrDefault(p => p.CityId == family.CityId);
     DTO.ChildWithFamilyDetails childWithDetails = new DTO.ChildWithFamilyDetails
     {
         IdentityNum      = child.IdentityNum,
         FamilyId         = child.FamilyId,
         FirstName        = child.FirstName,
         FamilyName       = family.FamilyName,
         FatherFirstName  = family.FatherFirstName,
         MotherFirstName  = family.MotherFirstName,
         NumOfChildren    = family.NumOfChildren,
         CityId           = family.CityId,
         Address          = family.Address,
         Telephone        = family.Telephone,
         Cellular1        = family.Cellular1,
         Cellular2        = family.Cellular2,
         Kind             = child.Kind,
         BirthDate        = child.BirthDate,
         PlaceInFamily    = child.PlaceInFamily,
         SchoolId         = child.SchoolId,
         Grade            = child.Grade,
         JoiningDate      = child.JoiningDate,
         ViturSodiutFrom  = child.ViturSodiutFrom,
         PreviousCare     = child.PreviousCare,
         Note             = child.Note,
         IsActive         = child.IsActive,
         IsMunicipality   = child.IsMunicipality,
         sumAfterDiscount = child.sumAfterDiscount,
         SchoolName       = school == null ? null : school.SchoolName,
         CityName         = city == null ? null : city.CityName
     };
     return(childWithDetails);
 }