public void Update(UpdateListMedicines _details)
        {
            //עדכון סטטוס התרופות לאחר שהמשתמש אישר שלקח אותם
            List <MedicinesToChild>    _medicinesToChild = _medicinesToChild_DAL.GetByUserInSomeTime(_details.CodeTimeToUser);
            List <ArchiveTakeMedicine> archives          = _archiveDAL.GetToDay(_details.CodeTimeToUser.UserID);

            foreach (var _medicines in _medicinesToChild)
            {
                if (_details.ListMedicines.Find(m => m.Id == _medicines.Id).Status)
                {
                    TimeToMedicinesForChild timeToMedicinesForChild = _medicines.TimeToMedicinesForChilds.First(m => m.TimeOfDay.timeCode == _details.CodeTimeToUser.TimeOfDay);
                    timeToMedicinesForChild.status = true;
                    _TimeToMedicinesForChild_DAL.Edit(timeToMedicinesForChild);
                    ArchiveTakeMedicine archiveTake = archives.Find(a => a.medicineToChild == timeToMedicinesForChild.Id);
                    archiveTake.time = DateTime.Now.TimeOfDay;
                    //archiveTake.onTime = !(_details.CountSnooze > timeToMedicinesForChild.MedicinesToChild.User.snoozeCounter);
                    User     user      = _User_DAL.GetByIdentity(_details.CodeTimeToUser.UserID);
                    int      maxMinute = (int)user.snoozePeriod * (int)user.snoozeCounter;
                    TimeSpan temp      = new TimeSpan(0, maxMinute, 0);
                    TimeSpan maxTime   = timeToMedicinesForChild.TimeOfDay.theTime.Add(temp);
                    temp = DateTime.Now.TimeOfDay;
                    //if (_details.CountSnooze <= timeToMedicinesForChild.MedicinesToChild.User.snoozeCounter / 2)
                    if (maxTime >= DateTime.Now.TimeOfDay)
                    {
                        temp = timeToMedicinesForChild.TimeOfDay.theTime;
                        int  count = 0;
                        bool flag  = true;
                        while (flag)
                        {
                            temp.Add(new TimeSpan(0, (int)user.snoozePeriod, 0));
                            count++;
                            if (temp >= DateTime.Now.TimeOfDay)
                            {
                                flag = false;
                            }
                        }
                        if (count <= timeToMedicinesForChild.MedicinesToChild.User.snoozeCounter / 2)
                        {
                            user.points += 2;
                        }
                        //if(temp <= timeToMedicinesForChild.TimeOfDay.theTime.Add(new TimeSpan(0,(int)timeToMedicinesForChild.MedicinesToChild.User.snoozeCounter / 2* (int)timeToMedicinesForChild.MedicinesToChild.User.snoozePeriod,0)))
                        else
                        {
                            user.points += 1;
                        }
                        archiveTake.onTime = true;
                        //למחוק מההתראות
                        Alert_BL.RemoveSnooze(_details.CodeTimeToUser);
                    }
                    else
                    {
                        archiveTake.onTime = false;
                    }
                    //else if (_details.CountSnooze <= timeToMedicinesForChild.MedicinesToChild.User.snoozeCounter)
                    _User_DAL.Edit(user);
                    _archiveDAL.Edit(archiveTake);
                }
            }
        }
Exemple #2
0
 public bool Add(TimeOfAlertForUser timeOfAlertForUser)
 {
     if (_user_DAL.AddSnooze(timeOfAlertForUser.snooze))                      //V
     {
         if (_TimeOfDay_DAL.AddListTimeOfAlert(timeOfAlertForUser.timeOfDay)) //V
         {
             //List<DetailsAlert>[] _DetailsOfAlert =_MedicinesToChild_DAL.AddListMedicinesToUser(timeOfAlertForUser);
             if (_MedicinesToChild_DAL.AddListMedicinesToUser(timeOfAlertForUser)) //V
             {
                 Alert_BL.AddTimesToMatForNewUser(timeOfAlertForUser);             //V
                 return(true);
             }
             return(false);
         }
         return(false);
     }
     return(false);
 }