Пример #1
0
        public bool UpdateMedicincesToUsersEveryDay()
        {
            List <User> users = _DB.Users.ToList();

            foreach (var user in users)
            {
                List <TimeOfDay> timesToMedicine = _TimeOfDay_DAL.GetListByUserId(user.Id);
                if (timesToMedicine.Count() != 0)
                {
                    List <Models.HMO_db.MedicinesToClient> medicinesToClients = _MedicinesToClient_DAL.GetByUserId(user.Id);
                    ArchiveDAL _archiveDAL = new ArchiveDAL();
                    if (medicinesToClients.Count != 0)
                    {
                        foreach (var item in medicinesToClients)
                        {
                            MedicinesToChild medicinesToChild = new MedicinesToChild()
                            {
                                medicineId   = item.medicinesId,
                                userId       = user.Id,
                                kindOfDosage = item.kindOfDosage,
                                Dosage       = item.Dosage,
                                date         = DateTime.Today
                            };
                            long medicinesToChildId = Add(medicinesToChild);


                            //עבור כל תרופה לילד להכניס לזמן לילד
                            //שליפה מזמנים לילד והצבה עם זמנים לקליינט
                            foreach (var timeToMed in item.TimeToMedicinesForClients)
                            {
                                TimeToMedicinesForChild timeToChild = new TimeToMedicinesForChild()
                                {
                                    idMedicineToChild = medicinesToChildId,
                                    idTimeOfDay       = timesToMedicine.First(t => t.timeCode == timeToMed.timeCode).timeId,//לבדוק
                                    status            = false
                                };

                                //_DB.TimeToMedicinesForChilds.Add(timeToChild);
                                long timeToMedicinesForChildId = _timeToMedicinesForChild_DAL.Add(timeToChild);
                                _archiveDAL.Add(
                                    new ArchiveTakeMedicine
                                {
                                    userId          = user.Id,
                                    medicineToChild = timeToMedicinesForChildId,
                                    date            = DateTime.Now.Date,
                                    onTime          = false
                                });
                            }
                        }
                    }
                }
            }
            if (_DB.SaveChanges() == 0)
            {
                return(false);
            }
            return(true);
        }