Exemple #1
0
        //returns the DiaryToddlerStatus line for a given toddler (and location)
        private DiaryToddlerStatus getDiaryToddlerStatus(Toddler tod)
        {
            DiaryToddlerStatus dts = db.DiaryToddlerStatus.FirstOrDefault(d => d.ToddlerId == tod.ToddlerId);//add location search

            if (dts == null)
            {
                DiaryToddlerStatus createNewDts = new DiaryToddlerStatus();
                createNewDts.Toddler = tod;
                createNewDts.Status  = (int)ChildStatus.Home;
                //add location
                if (location != null)
                {
                    createNewDts.Location = location;
                }
                try
                {
                    db.DiaryToddlerStatus.Add(createNewDts);
                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                dts = db.DiaryToddlerStatus.First(d => d.ToddlerId == tod.ToddlerId);
            }
            return(dts);
        }
Exemple #2
0
        public ActionResult CreateParentFromToddler(CreateParentViewModel cpvm)
        {
            Person parent = new Person();

            parent.Id        = Guid.NewGuid();
            parent.FirstName = cpvm.FirstName;
            parent.LastName  = cpvm.LastName;
            parent.Gender    = cpvm.Gender;
            db.People.Add(parent);


            Toddler toddler = GetToddler(cpvm.SubjectId);

            if (toddler == null)
            {
                db.SaveChanges();
                return(RedirectToAction("PersonIndex"));
            }


            ContactAssociation ca = NewContactAssociation(toddler.Id, parent.Id, Association.Parent);

            db.ContactAssociations.Add(ca);
            db.SaveChanges();
            return(RedirectToAction("ToddlerDetails", new { id = toddler.Id }));
        }
Exemple #3
0
        public ActionResult Delete(Guid?subjectid, bool?saveChangesError = false)
        {
            if (subjectid == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            if (saveChangesError.GetValueOrDefault())
            {
                ViewBag.ErrorMessage = "Delete failed. Try again, and if the problem persists see your system administrator.";
            }
            DeleteSubjectViewModel dsvm = new DeleteSubjectViewModel();
            Toddler t = db.Toddlers.Find(subjectid);

            if (t != null)
            {
                dsvm.id    = t.Id;
                dsvm.Line1 = t.FirstName;
                dsvm.Line2 = t.LastName;
                dsvm.Line3 = t.DayOfBirth.ToShortDateString();
                return(PartialView("_Delete", dsvm));
            }
            else
            {
                Person p = db.People.Find(subjectid);
                dsvm.id    = p.Id;
                dsvm.Line1 = p.FirstName;
                dsvm.Line2 = p.LastName;
                return(PartialView("_Delete", dsvm));
            }
        }
Exemple #4
0
        public List <ChildCard> GetChildCards()
        {
            DateTime         today     = DateTime.Now;
            string           dayOfWeek = DateTime.Now.DayOfWeek.ToString();
            List <Toddler>   toddlers  = db.Toddlers.Include(t => t.Person).Where(t => t.Person.Active == true).ToList();
            List <ChildCard> ccList    = new List <ChildCard>();

            if (toddlers != null)
            {
                foreach (Toddler t in toddlers)
                {
                    Toddler tod = t;
                    if (tod != null)
                    {
                        ChildCard cc = new ChildCard();
                        cc.Id     = tod.ToddlerId.ToString();
                        cc.Name   = tod.Person.FirstName;
                        cc.Photo  = tod.Person.Photo;
                        cc.Status = (ChildStatus)getDiaryToddlerStatus(tod).Status;
                        ccList.Add(cc);
                    }
                }
            }
            return(ccList);
        }
        public PartialViewResult ShowToddler(string toddlerOverview)
        {
            Toddler toddler;
            int     id = 0;

            if (int.TryParse(toddlerOverview, out id))
            {
                id = Int32.Parse(toddlerOverview);
            }
            if (id != 0)
            {
                toddler = db.Toddlers
                          .Where(i => i.ToddlerId.Equals(id))
                          .Include(p => p.Person)
                          .Include(f => f.Food)
                          .Include(s => s.Sleep)
                          .Include(m => m.Medical)
                          .Include(d => d.Medical.Doctor)
                          .Include(dp => dp.Medical.Doctor.Person)
                          .Include(dpa => dpa.Medical.Doctor.Person.Address)
                          .Include(dpc => dpc.Medical.Doctor.Person.ContactDetail)
                          .FirstOrDefault();

                ViewBag.Parents    = GetParentsOfToddler(toddler);
                ViewBag.Pickups    = GetPickupsOfToddler(toddler);
                ViewBag.AgreedDays = GetAgreedDaysOfToddler(toddler);
            }
            else
            {
                toddler = new Toddler();
            }
            return(PartialView("_OverviewShowToddler", toddler));
        }
Exemple #6
0
        public ActionResult <Toddler> PostToddler(Toddler toddler)
        {
            _unitOfWork.ToddlerRepository.Add(toddler);
            _unitOfWork.SaveChanges();

            return(CreatedAtAction("GetToddler", new { id = toddler.Id }, toddler));
        }
        /************** EDIT Pages ************/
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Overview"));
            }
            else
            {
                Toddler toddler = db.Toddlers
                                  .Where(i => i.ToddlerId == id)
                                  .Include(p => p.Person)
                                  .Include(f => f.Food)
                                  .Include(s => s.Sleep)
                                  .Include(m => m.Medical)
                                  .FirstOrDefault();

                EditToddler ec = new EditToddler();
                ec.toddler    = toddler;
                ec.parents    = GetParentsOfToddler(toddler);
                ec.pickups    = GetPickupsOfToddler(toddler);
                ec.agreedDays = GetAgreedDaysOfToddler(toddler);

                return(View(ec));
            }
        }
        /**AGREEDDAYSANDPICKUPS***************/
        // GET: Administration/Children/AgreedDaysAndPickups
        public PartialViewResult _AddAgreedDaysAndPickups()
        {
            Toddler toddler         = GetCurrentToddler();
            string  readyForDaycare = "";
            string  readyForSchool  = "";

            if (toddler != null)
            {
                DateTime birthdate = toddler.Person.BirthDate;

                if (birthdate != null)
                {
                    readyForDaycare = CalculateReadyForDaycare(birthdate);
                    readyForSchool  = CalculateReadyForSchool(birthdate);
                }
            }
            CreateAgreedDaysAndPickup caap = new CreateAgreedDaysAndPickup();

            caap.relationLinks  = GetRelationLinksOfCurrentToddler();
            caap.agreedDaysList = GetAgreedDaysOfCurrentToddler();
            caap.pickups        = GetPickupsOfCurrentToddler();
            caap.agreedDays     = new AgreedDays();
            caap.pickup         = new Pickup();

            ViewBag.ReadyForDaycare = readyForDaycare;
            ViewBag.ReadyForSchool  = readyForSchool;
            return(PartialView(caap));
        }
        public PartialViewResult CreateAgreedDays(CreateAgreedDaysAndPickup model)
        {
            string session = GetNewChildWizardSession();

            if (ModelState.IsValid)
            {
                Toddler    toddler    = GetCurrentToddler();
                AgreedDays agreedDays = new AgreedDays();

                agreedDays.ToddlerId = toddler.ToddlerId;

                agreedDays.StartDate = model.agreedDays.StartDate;
                agreedDays.EndDate   = model.agreedDays.EndDate;

                agreedDays.Monday    = (bool)model.agreedDays.Monday;
                agreedDays.Tuesday   = (bool)model.agreedDays.Tuesday;
                agreedDays.Wednesday = (bool)model.agreedDays.Wednesday;
                agreedDays.Thursday  = (bool)model.agreedDays.Thursday;
                agreedDays.Friday    = (bool)model.agreedDays.Friday;

                agreedDays.SpecialNotice = model.agreedDays.SpecialNotice;

                db.AgreedDays.Add(agreedDays);
                db.SaveChanges();
            }

            return(PartialView("_ListAgreedDays", GetAgreedDaysOfCurrentToddler()));
        }
Exemple #10
0
        public static Toddler getToddlerByIdMock(int id)
        {
            IEnumerable <Toddler> allToddlers = GetAllToddlersMock();
            Toddler selectedToddler           = allToddlers.Where(toddler => toddler.Id.Equals(id)).FirstOrDefault();

            return(selectedToddler);
        }
Exemple #11
0
        // This function will build the invoice for a given toddler. It will only create an invoice if there is a need for one.
        private void BuildInvoice(Toddler toddler)
        {
            Invoice  lastInvoice = getLastInvoice(toddler);
            DateTime startdate   = lastInvoice.CreationDate; // Startdate to calculate the extra days and closing days
            DateTime enddate     = DateTime.Now;             // This is the new CreationDate

            DateTime lastInvoicePeriod = new DateTime(lastInvoice.Year, lastInvoice.Month, 1);
            DateTime newInvoicePeriod  = lastInvoicePeriod.AddMonths(1); // This is done to handle december of a year and jump to the new year.

            int ndnm  = getAllAgreedDaysInMonth(toddler, newInvoicePeriod.Month, newInvoicePeriod.Year).Count;
            int edtm  = getAllExtraDaysinPeriod(toddler, startdate, enddate).Count;
            int dcctm = getAllClosingDaysInPeriod(toddler, startdate, enddate).Count;

            if (ndnm != 0 || edtm != 0 || dcctm != 0)
            {
                Invoice newInvoice = new Invoice();
                newInvoice.CreationDate           = enddate; // setting the new CreationDate
                newInvoice.Month                  = newInvoicePeriod.Month;
                newInvoice.Year                   = newInvoicePeriod.Year;
                newInvoice.Toddler                = toddler;
                newInvoice.NormalDaysNextMonth    = ndnm;
                newInvoice.ExtraDaysThisMonth     = edtm;
                newInvoice.DayCareClosedThisMonth = dcctm;
                newInvoice.Payed                  = false;
                newInvoice.HasSibling             = false;
                newInvoice.TotalAmount            = 0;
                newInvoice.OGM = buildOGM(toddler.ToddlerId, newInvoicePeriod.Month, newInvoicePeriod.Year);
                db.Invoices.Add(newInvoice);
                db.SaveChanges();
            }
        }
Exemple #12
0
        // GET: Diary/Diary/Diary
        public ActionResult Diary(Guid?c, DateTime date)
        {
            ViewBag.Class = c;
            List <AgreedDay>   ads = db.AgreedDays.Where(d => (d.Date.Day == date.Day && d.Date.Month == date.Month && d.Date.Year == date.Year) && d.ClassId == c).ToList();
            List <ToddlerCard> tcs = new List <ToddlerCard>();

            foreach (AgreedDay ad in ads)
            {
                Toddler t = db.Toddlers.Find(ad.ToddlerId);
                if (t != null)
                {
                    DiaryEntry  de = db.DiaryEntries.Where(en => (en.Date.Day == date.Day && en.Date.Month == date.Month && en.Date.Year == date.Year) && en.ToddlerId == t.Id && en.Status != DiaryEntryStatus.Other && en.Status != DiaryEntryStatus.VideoMessage).OrderByDescending(en => en.Date).FirstOrDefault();
                    ToddlerCard tc;
                    if (de != null)
                    {
                        tc = new ToddlerCard {
                            Name = t.FirstName, ToddlerId = t.Id, Status = de.Status
                        };
                    }
                    else
                    {
                        tc = new ToddlerCard {
                            Name = t.FirstName, ToddlerId = t.Id, Status = DiaryEntryStatus.NotArrived
                        };
                    }
                    tcs.Add(tc);
                }
            }
            return(View(tcs));
        }
Exemple #13
0
        public ActionResult ToddlerInfo(Guid?subjectid)
        {
            ToddlerInfoViewModel tivm = new ToddlerInfoViewModel();

            Toddler t = db.Toddlers.Find(subjectid);

            if (t != null)
            {
                tivm.Id        = t.Id;
                tivm.FirstName = t.FirstName;
                tivm.LastName  = t.LastName;
                tivm.BirthDate = t.DayOfBirth;
                foreach (Person p in t.Parents)
                {
                    tivm.Parents.Add(p.FirstName + " " + p.LastName);
                }
                foreach (Toddler s in t.Siblings)
                {
                    tivm.Siblings.Add(s.FirstName + " " + s.LastName);
                }
            }
            else
            {
                return(PartialView("_ToddlerInfo"));
            }

            return(PartialView("_ToddlerInfo", tivm));
        }
        //Mocking a scan


        public void tripScan()
        {
            //Create a new scan
            //Scan returns name and last name from a toddler
            //Get toddler from database
            //Add that toddler to a list
            //If needed, scan another toddler
            scannedToddler1 = _toddlerService.getToddlerById(1);
            scannedToddlers.Add(scannedToddler1);
            scannedToddler2 = _toddlerService.getToddlerById(2);
            scannedToddlers.Add(scannedToddler2);
            //Do a lookup in the database for the correct Trip
            trip = _tripService.getTripById(1);
            //Do a lookup in the database for the correct Teacher
            teacher = _teacherService.getTeacherById(1);
            //Create a new Scan with gathered data
            scan = new Scan
            {
                Id        = 5,
                Name      = _tripName,
                TeacherId = teacher.Id,
                teacher   = teacher,
                TripId    = trip.Id,
                trip      = trip,
                Toddlers  = scannedToddlers
            };
            Debug.WriteLine($"Number of scans before add is: {_scanService.allScans().Count}");
            _scanService.addScan(scan);
            _scanConfirmed = Constant.ScanConfirmed;
            OnPropertyChanged(Constant.ScanConfirmedProperty);
            Debug.WriteLine($"Number of scans after add is: {_scanService.allScans().Count}");
        }
Exemple #15
0
 public async void Post([FromBody] Toddler toddler)
 {
     using (context)
     {
         EntityEntry <Toddler> teacherEntery = context.Toddlers.Add(toddler);
         await context.SaveChangesAsync();
     }
 }
        public async Task <Toddler> PostToddler(Toddler toddler)
        {
            UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl)
            {
                Path = ApiConstants.BaseApiUriPart + ApiConstants.PostToddlerEndpoint
            };

            return(await _genericRepository.PostAsync <Toddler>(builder.ToString(), toddler));
        }
Exemple #17
0
 public Child(Toddler toddler, ICollection <Parent> parents, ChildStatus status)
 {
     this.Status  = status;
     this.Toddler = toddler;
     this.Id      = toddler.ToddlerId.ToString();
     this.Name    = toddler.Person.FirstName;
     this.Photo   = toddler.Person.Photo;
     this.Parents = parents;
 }
Exemple #18
0
 public ActionResult ToddlerDetails([Bind(Include = "Id, FirstName, LastName, Gender, DayOfBirth, GuaranteePrice")] Toddler toddler)
 {
     if (ModelState.IsValid)
     {
         db.Entry(toddler).State = EntityState.Modified;
         db.SaveChanges();
     }
     return(RedirectToAction("ToddlerDetails", toddler.Id));
 }
Exemple #19
0
        public async override void OnNavigatedTo(NavigationParameters parameters)
        {
            if (parameters.ContainsKey("Toddler"))
            {
                selectedToddler = (Toddler)parameters["Toddler"];
            }

            repos = new CameraatjeRepository(dbContext);
        }
Exemple #20
0
        // return ChildCard for each child that has to come today
        public List <ChildCard> GetChildCardsForToday()
        {
            DateTime          today          = DateTime.Now;
            DateTime          todaydate      = DateTime.Now.Date;
            string            dayOfWeek      = DateTime.Now.DayOfWeek.ToString();
            List <AgreedDays> agreedDaysList = whoHasToComeToday(dayOfWeek, today);
            List <ChildCard>  ccList         = new List <ChildCard>();

            if (agreedDaysList != null)
            {
                foreach (AgreedDays AD in agreedDaysList)
                {
                    Toddler tod = getToddler(AD.ToddlerId);
                    if (tod != null)
                    {
                        ChildCard cc = new ChildCard();
                        cc.Id     = tod.ToddlerId.ToString();
                        cc.Name   = tod.Person.FirstName;
                        cc.Photo  = tod.Person.Photo;
                        cc.Status = (ChildStatus)getDiaryToddlerStatus(tod).Status;
                        ccList.Add(cc);


                        // Creating RegisteredDay with checkedIn == false

                        RegisteredDay rd = db.RegisteredDays.Where(rdc => (rdc.ToddlerId == tod.ToddlerId) && (rdc.DayInDaycare == todaydate)).FirstOrDefault();
                        if (rd == null || rd.RegisteredDayId == 0)
                        {
                            rd = new RegisteredDay();
                            rd.DayInDaycare    = todaydate;
                            rd.CheckedIn       = false;
                            rd.DaycareIsClosed = false;
                            rd.ExtraDay        = false;
                            rd.Toddler         = tod;
                            db.RegisteredDays.Add(rd);
                            db.SaveChanges();
                        }
                    }
                }
            }
            List <RegisteredDay> extraDays = db.RegisteredDays.Include(erd => erd.Toddler).Include(erd => erd.Toddler.Person).Where(erd => (erd.ExtraDay == true) && (erd.DayInDaycare == todaydate)).ToList();

            if (extraDays != null)
            {
                foreach (RegisteredDay rd in extraDays)
                {
                    ChildCard cc = new ChildCard();
                    cc.Id     = rd.ToddlerId.ToString();
                    cc.Name   = rd.Toddler.Person.FirstName;
                    cc.Photo  = rd.Toddler.Person.Photo;
                    cc.Status = (ChildStatus)getDiaryToddlerStatus(rd.Toddler).Status;
                    ccList.Add(cc);
                }
            }
            return(ccList);
        }
        public ICollection <AgreedDays> GetAgreedDaysOfToddler(Toddler toddler)
        {
            ICollection <AgreedDays> agreedDaysList = new List <AgreedDays>();

            if (toddler != null)
            {
                agreedDaysList = db.AgreedDays.Where(t => t.ToddlerId == toddler.ToddlerId).ToList();
            }
            return(agreedDaysList);
        }
Exemple #22
0
        public ActionResult CreateToddlerShortInfo([Bind(Include = "FirstName, LastName, Gender, DayOfBirth")] Toddler toddler)
        {
            Guid id = Guid.NewGuid();

            toddler.Id = id;
            db.Toddlers.Add(toddler);
            db.SaveChanges();

            return(RedirectToAction("ToddlerDetails", new { id = id }));
        }
Exemple #23
0
        // This function will generate a list of all the days the toddler will come next month.

        /*
         *  Get the Agreed days for nex month
         *  Generate every day in the next month
         *  Check if the toddler has to come that day
         *  Add that day to the list
         */
        private List <DateTime> getAllAgreedDaysInMonth(Toddler t, int year, int month)
        {
            List <DateTime> ADays       = new List <DateTime>();
            AgreedDays      ADnextMonth = agreedDaysThatApply(t, year, month);
            int             days        = DateTime.DaysInMonth(year, month);

            for (int day = 1; day <= days; day++)
            {
                DateTime thisDay = new DateTime(year, month, day);
                if (thisDay >= ADnextMonth.StartDate && thisDay <= ADnextMonth.EndDate)
                {
                    switch (thisDay.DayOfWeek)
                    {
                    case DayOfWeek.Monday:
                        if (ADnextMonth.Monday == true)
                        {
                            ADays.Add(thisDay);
                        }
                        break;

                    case DayOfWeek.Tuesday:
                        if (ADnextMonth.Tuesday == true)
                        {
                            ADays.Add(thisDay);
                        }
                        break;

                    case DayOfWeek.Wednesday:
                        if (ADnextMonth.Wednesday == true)
                        {
                            ADays.Add(thisDay);
                        }
                        break;

                    case DayOfWeek.Thursday:
                        if (ADnextMonth.Thursday == true)
                        {
                            ADays.Add(thisDay);
                        }
                        break;

                    case DayOfWeek.Friday:
                        if (ADnextMonth.Friday == true)
                        {
                            ADays.Add(thisDay);
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
            return(ADays);
        }
        public ActionResult Create(int?id)
        {
            Toddler toddler = GetCurrentToddler();
            ICollection <Parent> parents = GetParentsOfCurrentToddler();

            toddler.Person.Active = true;

            db.Entry(toddler).State = EntityState.Modified;
            db.SaveChanges();

            string emailIsDouble = "";

            foreach (Parent parent in parents)
            {
                string email = parent.Person.ContactDetail.Email;
                parent.Person.Active = true;

                /*if (email != emailIsDouble)
                 * {
                 *  var UserManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));
                 *  parent.Person.UserAccount = new ApplicationUser();
                 *  parent.Person.UserAccount.UserName = email;
                 *  parent.Person.UserAccount.Email = email;
                 *
                 *  string userPWD = Membership.GeneratePassword(6, 1);
                 *
                 *  var chkUser = UserManager.Create(parent.Person.UserAccount, userPWD);
                 *
                 *  MailService ms = new MailService();
                 *  CreateNewAccount cna = new CreateNewAccount();
                 *  cna.firstname = parent.Person.FirstName;
                 *  cna.email = email;
                 *  cna.password = userPWD;
                 *
                 *  //ms.SendMail(cna);
                 * }
                 * else
                 * {
                 *  parent.Person.UserAccountId = db.Users.Where(e => e.Email == emailIsDouble).FirstOrDefault().Id;
                 * }
                 */
                db.Entry(parent).State = EntityState.Modified;
                db.SaveChanges();
                emailIsDouble = email;
            }

            //NewChildWizardSession ncws = db.NewChildWizardSessions.Where(s => s.ToddlerSession == toddler.ToddlerSession).FirstOrDefault();

            //ncws.Stop = DateTime.Now;
            //ncws.Complete = true;
            //db.Entry(ncws).State = EntityState.Modified;

            //db.SaveChanges();
            return(RedirectToAction("Overview", "Children"));
        }
Exemple #25
0
        // Returns all the extra days the child has come that are not in the AgreedDays. startdate = creationdate last created invoice, enddate = creationdate new invoice
        private List <DateTime> getAllExtraDaysinPeriod(Toddler t, DateTime startdate, DateTime enddate)
        {
            List <RegisteredDay> extraRegisteredDays = db.RegisteredDays.Where(rd => (rd.CheckedIn == true) && (rd.ExtraDay == true)).ToList();
            List <DateTime>      extraDays           = new List <DateTime>();

            foreach (RegisteredDay rd in extraRegisteredDays)
            {
                extraDays.Add(rd.DayInDaycare);
            }
            return(extraDays);
        }
Exemple #26
0
 public ChangeGradeViewModel(INavigationService navigation)
 {
     MessagingCenter.Subscribe <Application, Toddler>(this, Constant.SendToddlerInformation, (e, toddler) =>
     {
         _selectedtoddler = toddler;
         Debug.WriteLine("in subscribe " + _selectedtoddler + " " + toddler);
         OnPropertyChanged(Constant.SelectedToddlerProperty);
     });
     _navigation = navigation;
     changeGradeButtonClicked = new Command(onSubmit);
 }
        public async Task <Toddler> PutToddler(long toddlerId, Toddler toddler)
        {
            toddler.Class = null;

            UriBuilder builder = new UriBuilder(ApiConstants.BaseApiUrl)
            {
                Path = ApiConstants.BaseApiUriPart + ApiConstants.PutToddlerEndpoint + toddlerId
            };

            return(await _genericRepository.PutAsync <Toddler>(builder.ToString(), toddler));
        }
        public PartialViewResult CreateToddler(CreateToddlerOverview model)
        {
            if (ModelState.IsValid)
            {
                Toddler toddler = new Toddler();
                toddler.ToddlerSession = GetNewChildWizardSession();

                toddler.Person                  = new Person();
                toddler.Person.FirstName        = model.toddler.Person.FirstName;
                toddler.Person.LastName         = model.toddler.Person.LastName;
                toddler.Person.Gender           = model.toddler.Person.Gender;
                toddler.Person.BirthDate        = model.toddler.Person.BirthDate;
                toddler.Person.RegistrationDate = DateTime.Now;
                toddler.Person.Active           = false;
                if (model.toddler.Person.Gender == "male")
                {
                    toddler.Person.Photo = "baby-boy.png";
                }
                else if (model.toddler.Person.Gender == "female")
                {
                    toddler.Person.Photo = "baby-girl.png";
                }
                else
                {
                    toddler.Person.Photo = "stork.png";
                }

                //newToddler = toddler; // TRYOUT

                db.Toddlers.Add(toddler);
                db.SaveChanges();

                RelationLink relationLink = new RelationLink();
                relationLink.RelationToChild = "isChild";
                relationLink.Toddler         = db.Toddlers.Find(toddler.ToddlerId);
                relationLink.Person          = db.Persons.Find(toddler.Person.PersonId);

                //newRelationLinks.Add(relationLink); // TRYOUT

                db.RelationLinks.Add(relationLink);
                db.SaveChanges();

                //db.NewChildWizardSessions.Add(ncws);
                //db.SaveChanges();

                return(PartialView("_ListToddler", toddler));
            }
            else
            {
                Toddler current = GetCurrentToddler();
                return(PartialView("_ListToddler", current));
            }
        }
Exemple #29
0
        private Toddler GetToddler(Guid?id)
        {
            Toddler t = db.Toddlers.Find(id);

            if (t == null)
            {
                return(null);
            }

            t.AgreedPeriods = db.AgreedPeriods.Where(ap => ap.ToddlerId == id).ToList();

            List <ContactAssociation> Associations = GetContactAssociations(t.Id);

            foreach (ContactAssociation ca in Associations)
            {
                switch (ca.Association)
                {
                case Association.Parent:
                    if (ca.Contact1Id == id)
                    {
                        t.Parents.Add(db.People.Find(ca.Contact2Id));
                    }
                    else
                    {
                        t.Parents.Add(db.People.Find(ca.Contact1Id));
                    }
                    break;

                case Association.Pickup:
                    if (ca.Contact1Id == id)
                    {
                        t.Pickups.Add(db.People.Find(ca.Contact2Id));
                    }
                    else
                    {
                        t.Pickups.Add(db.People.Find(ca.Contact1Id));
                    }
                    break;

                case Association.Sibling:
                    if (ca.Contact1Id == id)
                    {
                        t.Siblings.Add(db.Toddlers.Find(ca.Contact2Id));
                    }
                    else
                    {
                        t.Siblings.Add(db.Toddlers.Find(ca.Contact1Id));
                    }
                    break;
                }
            }
            return(t);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Scan>()
            .HasMany(s => s.ToddlerScans);

            modelBuilder.Entity <Trip>()
            .HasMany(t => t.Toddlers);

            modelBuilder.Entity <Toddler>()
            .Property(t => t.FirstName)
            .IsRequired();

            Toddler toddlerSeed = new Toddler
            {
                Id        = 1,
                FirstName = "Kevin",
                LastName  = "Traets",
                Grade     = "3"
            };
            Teacher teacherSeed = new Teacher
            {
                Id        = 1,
                FirstName = "Kris",
                LastName  = "Hermans"
            };

            Trip tripSeed = new Trip
            {
                Id        = 1,
                Date      = DateTime.Now,
                TeacherId = teacherSeed.Id,
                Title     = "Zee"
            };
            Scan scanSeed = new Scan
            {
                Id        = 1,
                Name      = "Middagpauze",
                TeacherId = teacherSeed.Id,
                TripId    = tripSeed.Id,
            };
            ToddlerTrip toddlerTripSeed = new ToddlerTrip
            {
                Id        = 1,
                ToddlerId = toddlerSeed.Id,
                TripId    = tripSeed.Id
            };

            modelBuilder.Entity <Toddler>().HasData(toddlerSeed);
            modelBuilder.Entity <Teacher>().HasData(teacherSeed);
            modelBuilder.Entity <Trip>().HasData(tripSeed);
            modelBuilder.Entity <Scan>().HasData(scanSeed);
            modelBuilder.Entity <ToddlerTrip>().HasData(toddlerTripSeed);
        }