Example #1
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);
        }
Example #2
0
        // Sends the child update to the database (diary entry)
        public void SetChildUpdate(string ChildId, ChildUpdate update, String comment)
        {
            foreach (Child c in children)
            {
                if (c.Id == ChildId)
                {
                    //Toggles between sleep and wake up (because its only one button)
                    ChildUpdate realUpdate = update;
                    if (c.Status == ChildStatus.Sleeping && update == ChildUpdate.Sleeping)
                    {
                        realUpdate = ChildUpdate.WakeUp;
                    }
                    //If the child is at home, you can't do anything else than check it in or place a comment. (safetycheck)
                    if (c.Status == ChildStatus.Home && (update != ChildUpdate.CheckIn && update != ChildUpdate.Comment))
                    {
                        return;
                    }
                    // CheckIn on registeredday
                    if (update == ChildUpdate.CheckIn)
                    {
                        DateTime todaydate = DateTime.Now.Date;

                        RegisteredDay rd = db.RegisteredDays.Where(rdc => (rdc.ToddlerId == c.Toddler.ToddlerId) && (rdc.DayInDaycare == todaydate)).FirstOrDefault();
                        if (rd != null || rd.ToddlerId != 0)
                        {
                            rd.CheckedIn = true;
                            db.SaveChanges();
                        }
                    }
                    //Send diary entry to database (DiaryToddlerUpdate)
                    try
                    {
                        DiaryToddlerUpdate dtu = new DiaryToddlerUpdate();
                        dtu.Toddler    = db.Toddlers.Find(c.Toddler.ToddlerId);
                        dtu.Timestamp  = DateTime.Now;
                        dtu.UpdateType = (int)realUpdate;
                        if (comment != null)
                        {
                            dtu.Comment = comment;
                        }
                        db.DiaryToddlerUpdate.Add(dtu);
                        db.SaveChanges();
                    }
                    catch { }
                }
            }
        }
Example #3
0
        // Add ExtraDay for a child
        public void AddExtraDay(string childId)
        {
            int  idint = 0;
            bool tryit = int.TryParse(childId, out idint);

            if (idint != 0)
            {
                Toddler tod = getToddler(idint);
                if (tod != null)
                {
                    RegisteredDay rd = new RegisteredDay();
                    rd.DayInDaycare    = DateTime.Now.Date;
                    rd.CheckedIn       = false;
                    rd.DaycareIsClosed = false;
                    rd.ExtraDay        = true;
                    rd.Toddler         = tod;
                    db.RegisteredDays.Add(rd);
                    db.SaveChanges();
                }
            }
        }