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); } } }
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); }
public void AddOrEdit(TimeToMedicinesForChild details) { if (details.Id == 0) { _TimeToMedicinesForChild_DAL.Add(details); } else { _TimeToMedicinesForChild_DAL.Edit(details); } }
//public bool AddListMedicinesToUser(long userId, List<TimeOfDay> listTimeOfDays) //public List<DetailsAlert>[] AddListMedicinesToUser(TimeOfAlertForUser timeOfAlertForUser) public bool AddListMedicinesToUser(TimeOfAlertForUser timeOfAlertForUser) { //V // List<DetailsAlert>[] _DetailsOfAlert = new List<DetailsAlert>[4]; //for (int i = 0; i < 4; i++) //{ // _DetailsOfAlert[i] = new List<DetailsAlert>(); //} List <Models.HMO_db.MedicinesToClient> medicinesToClients = _MedicinesToClient_DAL.GetByUserId(timeOfAlertForUser.snooze.userId); if (medicinesToClients.Count() != 0) { foreach (var item in medicinesToClients) { //_DB.Medicines.Add(new Medicine() { medicineId = item.medicineId, midicineName = item.midicineName }); MedicinesToChild medicinesToChild = new MedicinesToChild() { medicineId = item.medicinesId, userId = timeOfAlertForUser.snooze.userId, kindOfDosage = item.kindOfDosage, Dosage = item.Dosage, date = DateTime.Today }; long medicinesToChildId = Add(medicinesToChild);//V //V List <TimeToMedicinesForClient> timesToMedicine = _timeToMedicinesForClient_DAL.GetTimeOfDaysByTimeMidicineToClient(item.Id); if (timesToMedicine.Count() != 0) { foreach (var timeList in timesToMedicine) { TimeToMedicinesForChild timeToMedicinesForChild = new TimeToMedicinesForChild() { idMedicineToChild = medicinesToChildId, //idTimeOfDay = listTimeOfDays.Find(t => t.timeCode == item.TimeToMedicinesForClients.Where(tC => tC.TimeOfDay.timeId)).timeId idTimeOfDay = timeOfAlertForUser.timeOfDay.Find(t => t.timeCode == timeList.timeCode).timeId }; _timeToMedicinesForChild_DAL.Add(timeToMedicinesForChild); //User user = _User_DAL.GetByIdentity(timeOfAlertForUser.snooze.userId); //DetailsAlert detailsAlert = new DetailsAlert() //{ // UserToken = user.token, // AlertCount = 0, // UserName = user.userName, // snooze = new Snooze // { // userId = user.Id, // snoozePeriod = (int)user.snoozePeriod, // snoozeCounter = (int)user.snoozeCounter.Value, // }, // CodeTime = timeList.timeCode //}; //_DetailsOfAlert[timeList.timeCode - 1].Add(detailsAlert); } // int codeTimeToClient = item.TimeToMedicinesForClients.FirstOrDefault(t=>t.TimeOfDay.timeCode) } } } else if (_DB.SaveChanges() == 0) { return(false); } return(true); }