public static int addKinderGardenToTeacher(List <int> listKG, string id) { List <KinderGardenOfTeacher> k = new List <KinderGardenOfTeacher>(); foreach (var item in listKG) { KinderGardenOfTeacher k1 = new KinderGardenOfTeacher(); k1.IdKinderGarden = item; k1.IdTeacher = id; k.Add(k1); } using (NDBEntities db = new NDBEntities()) { try { foreach (var item in k) { db.KinderGardenOfTeacher.Add(item); db.SaveChanges(); } return(1); } catch (Exception) { throw; } } }
public static void addUser(CUsers cu) { Users u = Mapper.convertToUsers(cu); using (NDBEntities db = new NDBEntities()) { Users u2 = (from x in db.Users where x.IdUser.Equals(u.IdUser) && x.Permission != u.Permission && x.Permission != 4 select x).FirstOrDefault(); if (u2 != null) { db.Users.Find(u2.IdUser).Permission = 4; db.SaveChanges(); } else { try { db.Users.Add(u); db.SaveChanges(); } catch (Exception e) { throw e; } } } }
//public static void updateKinderGarden(CKinderGarden ck) //{ // CKinderGarden ck1 = selectKinderByCode(ck.IdKinderGarden); // if (ck1 != null) // { // ck1.Name = ck.Name; // ck1.Address = ck.Address; // ck1.Phone = ck.Phone; // ck1.Year = ck.Year; // ck1.BeginingHour = ck.BeginingHour; // ck1.Space = ck.Space; // } // else // { // addKinderGarden(ck); // } //} //public static List<CKinderGarden> selectKinderGardenByHour() //{ // List<CKinderGarden> listCKinderGarden = new List<CKinderGarden>(); // using (NDBEntities db = new NDBEntities()) // { // listCKinderGarden=(from x in db.KinderGarden // where x.BeginingHour.Hours>=DateTime.Now.Hour) // } //} public static List <CKinderGarden> selectKinderGardenByIdTeacher(string id) { List <KinderGardenOfTeacher> KGL = new List <KinderGardenOfTeacher>(); List <KinderGarden> KG = new List <KinderGarden>(); List <CKinderGarden> CKG = new List <CKinderGarden>(); using (NDBEntities db = new NDBEntities()) { KGL = (from x in db.KinderGardenOfTeacher where x.IdTeacher == id select x).ToList(); foreach (var item in KGL) { KinderGarden k = (from x in db.KinderGarden where item.IdKinderGarden == x.IdKinderGarden select x).FirstOrDefault(); KG.Add(k); } } if (KG != null) { foreach (var item in KG) { CKG.Add(Mapper.convertToCKinderGarden(item)); } } return(CKG); }
//public static void updateChildren(CChildren cc) //{ // if (selectchildrenById(cc.Id) != null) // { // removeChildren(cc.Id); // } // addChildren(cc); //} public static void updateChildren(CChildren cc) { Children c = Mapper.convertToChildren(selectchildrenById(cc.Id)); using (NDBEntities db = new NDBEntities()) { db.Children.Find(cc.Id).Address = cc.Address; db.Children.Find(cc.Id).Phone = cc.Phone; db.SaveChanges(); } }
public static int GetPermissionOfUser(string idUser) { using (NDBEntities db = new NDBEntities()) { Users u = (from x in db.Users where x.IdUser.Equals(idUser) select x).FirstOrDefault(); return(u.Permission); } }
public static CLiveData addLiveData(CLiveData cl) { LiveData l = Mapper.convertToLiveData(cl); using (NDBEntities db = new NDBEntities()) { db.LiveData.Add(l); db.SaveChanges(); } return(Mapper.convertToCLiveData(l)); }
//public static void updateUser(CUsers cu) //{ // if (selectUserById(cu.Id) != null) // { // removeUser(cu.Id); // } // addUser(cu); //} public static void updateUser(CUsers cu) { Users u = Mapper.convertToUsers(selectUserById(cu.Id)); using (NDBEntities db = new NDBEntities()) { db.Users.Find(cu.Id).Address = cu.Address; db.Users.Find(cu.Id).PhoneNum = cu.PhoneNum; db.Users.Find(cu.Id).MailAddress = cu.mailAddress; db.SaveChanges(); } }
public static CPreviousData selectPreviousByIdChild(string id) { PreviousData p = new PreviousData(); using (NDBEntities db = new NDBEntities()) { p = (from x in db.PreviousData where x.IdChild.Equals(id) select x).FirstOrDefault(); } return(Mapper.converToCPreviousData(p)); }
public static void ChangeStatus(string idChild, General.Statuses status) { LiveData l = new LiveData(); int newStatus = Mapper.StatusEnumToInt(status); using (NDBEntities db = new NDBEntities()) { l = db.LiveData.First(d => d.IdChild.Equals(idChild)); l.Status = newStatus; // l= db.LiveData.Find(idChild); db.SaveChanges(); } }
public static void updateFutureData(CFutureData CFutureData) { FutureData futureData = Mapper.convertToFutureData(selectFutureByIdChildAndDate(CFutureData.IdChild, CFutureData.Date)); using (NDBEntities db = new NDBEntities()) { futureData = db.FutureData.First(d => d.IdChild == CFutureData.IdChild); futureData.Alarm = CFutureData.Alarm; futureData.UpdateBy = CFutureData.UpdateBy; futureData.Comments = CFutureData.Comments; futureData.Status = Mapper.StatusEnumToInt(CFutureData.Status); db.SaveChanges(); } }
public static CUsers Login(string userId, string firstName, string lastName) { using (NDBEntities db = new NDBEntities()) { Users u = (from x in db.Users where x.IdUser.Equals(userId) && x.FirstName.Equals(firstName) && x.LastName.Equals(lastName) select x).FirstOrDefault(); if (u != null) { return(Mapper.convertToCUsers(u)); } return(null); } }
public static CUsers selectUserByParameters(string id, string FirstName, string LastName) { using (NDBEntities db = new NDBEntities()) { Users u = (from x in db.Users where x.IdUser.Equals(id) && x.FirstName.Equals(FirstName) && x.LastName.Equals(LastName) select x).FirstOrDefault(); if (u != null) { return(Mapper.convertToCUsers(u)); } return(null); } }
public static CKinderGarden selectKinderByCode(int code) { using (NDBEntities db = new NDBEntities()) { KinderGarden k = (from x in db.KinderGarden where x.IdKinderGarden == code select x).FirstOrDefault(); if (k != null) { return(Mapper.convertToCKinderGarden(k)); } return(null); } }
public static CLiveData selectLiveDataByIdChild(string id) { using (NDBEntities db = new NDBEntities()) { foreach (var l in db.LiveData) { if (l.IdChild.Equals(id)) { return(Mapper.convertToCLiveData(l)); } } return(null); } }
public static CChildren selectchildrenById(string id) { using (NDBEntities db = new NDBEntities()) { Children c = (from x in db.Children where x.IdChild.Equals(id) select x).FirstOrDefault(); if (c != null) { return(Mapper.convertToCChildren(c)); } return(null); } }
public static CUsers selectUserById(string id) { using (NDBEntities db = new NDBEntities()) { Users u = (from x in db.Users where x.IdUser.Equals(id) select x).FirstOrDefault(); if (u != null) { return(Mapper.convertToCUsers(u)); } return(null); } }
public static void copyLiveToPreviousData() { CPreviousData cp = new CPreviousData(); List <CLiveData> listCLiveData = DLiveDataManager.selectAllLiveData(); using (NDBEntities db = new NDBEntities()) { foreach (var item in listCLiveData) { db.PreviousData.Add(Mapper.converCLiveToPreviousData(item)); // db.LiveData.Remove(Mapper.convertToLiveData(item)); db.SaveChanges(); } } }
public static void removeAllLiveData() { List <LiveData> listLiveData = new List <LiveData>(); using (NDBEntities db = new NDBEntities()) { listLiveData = (from x in db.LiveData select x).ToList(); foreach (var item in listLiveData) { db.LiveData.Remove(item); db.SaveChanges(); } } }
public static CKinderGarden updateKinderGarden(CKinderGarden cc) { KinderGarden k = new KinderGarden(); CKinderGarden ck = new CKinderGarden(); using (NDBEntities db = new NDBEntities()) { db.KinderGarden.Find(cc.IdKinderGarden).Address = cc.Address; db.KinderGarden.Find(cc.IdKinderGarden).PhoneNumber = cc.Phone; db.KinderGarden.Find(cc.IdKinderGarden).BeginingHour = cc.BeginingHour; db.SaveChanges(); k = db.KinderGarden.Find(cc.IdKinderGarden); } ck = Mapper.convertToCKinderGarden(k); return(ck); }
public static CFutureData selectFutureByIdChildAndDate(string idChild, DateTime date) { FutureData futureData = new FutureData(); using (NDBEntities db = new NDBEntities()) { futureData = (from x in db.FutureData where x.Date.Equals(date) && x.IdChild.Equals(idChild) select x).FirstOrDefault(); if (futureData != null) { return(Mapper.convertToCFuteureData(futureData)); } return(null); } }
public static List <CLiveData> selectLiveDataByKinderGardenCode(int KinderGardenCode) { List <CLiveData> ld = new List <CLiveData>(); using (NDBEntities db = new NDBEntities()) { foreach (var l in db.LiveData) { if (l.KindergardenCode.Equals(KinderGardenCode)) { ld.Add(Mapper.convertToCLiveData(l)); } } return(ld); } }
public static List <CLiveData> selectAllLiveData() { List <LiveData> listLiveData = new List <LiveData>(); using (NDBEntities db = new NDBEntities()) { listLiveData = db.LiveData.ToList <LiveData>(); } List <CLiveData> listCLiveData = new List <CLiveData>(); foreach (var item in listLiveData) { listCLiveData.Add(Mapper.convertToCLiveData(item)); } return(listCLiveData); }
public static int UserIs(string idUser) { Users user = new Users(); using (NDBEntities db = new NDBEntities()) { user = (from x in db.Users where x.IdUser.Equals(idUser) select x).FirstOrDefault(); } if (user == null) { return(0); } return(1); }
public static List <CUsers> selectAllUsers() { List <Users> listUsers = new List <Users>(); using (NDBEntities db = new NDBEntities()) { listUsers = (from x in db.Users select x).ToList(); } List <CUsers> listCUsers = new List <CUsers>(); foreach (var item in listUsers) { listCUsers.Add(Mapper.convertToCUsers(item)); } return(listCUsers); }
public static List <CKinderGarden> selectAllKinderGarden() { List <KinderGarden> listKinderGarden = new List <KinderGarden>(); using (NDBEntities db = new NDBEntities()) { listKinderGarden = (from x in db.KinderGarden select x).ToList(); } List <CKinderGarden> lCKinderGarden = new List <CKinderGarden>(); foreach (var item in listKinderGarden) { lCKinderGarden.Add(Mapper.convertToCKinderGarden(item)); } return(lCKinderGarden); }
public static void addKinderGarden(CKinderGarden ck) { KinderGarden k = Mapper.convertToKinderGarden(ck); using (NDBEntities db = new NDBEntities()) { try { db.KinderGarden.Add(k); db.SaveChanges(); } catch (Exception) { throw; } } }
public static void addFutureData(CFutureData cf) { FutureData f = Mapper.convertToFutureData(cf); using (NDBEntities db = new NDBEntities()) { try { db.FutureData.Add(f); db.SaveChanges(); } catch (Exception) { throw; } } }
public static List <CFutureData> readAllFutureData() { List <FutureData> listFutureData = new List <FutureData>(); using (NDBEntities db = new NDBEntities()) { listFutureData = (from x in db.FutureData select x).ToList(); } List <CFutureData> listCFuture = new List <CFutureData>(); foreach (var item in listFutureData) { listCFuture.Add(Mapper.convertToCFuteureData(item)); } return(listCFuture); }
public static List <CLiveData> selectLiveIsNonPresent() { List <LiveData> ld = new List <LiveData>(); List <CLiveData> cld = new List <CLiveData>(); using (NDBEntities db = new NDBEntities()) { ld = (from x in db.LiveData where (x.Alarm.Hours < DateTime.Now.Hour || x.Alarm.Hours == DateTime.Now.Hour && x.Alarm.Minutes <= DateTime.Now.Minute) && (x.Status == 4 || x.Status == 1) select x).ToList(); } foreach (var item in ld) { cld.Add(Mapper.convertToCLiveData(item)); } return(cld); }
public static List <CFutureData> selectByIdChild(string id) { List <FutureData> listFutureData = new List <FutureData>(); using (NDBEntities db = new NDBEntities()) { listFutureData = (from x in db.FutureData where x.IdChild.Equals(id) select x).ToList(); List <CFutureData> listCFuture = new List <CFutureData>(); foreach (var item in listFutureData) { listCFuture.Add(Mapper.convertToCFuteureData(item)); } return(listCFuture); } }