public static List <Learner> getAllLearners() { using (BTProjectEntities db = new BTProjectEntities()) { return(Learner.cToDTO(db.learners_tbl.ToList())); } }
/// <summary> /// פונקציה לשליפת כל הספרים--- הבקשות של תורם מסוים /// </summary> /// <param name="donorEmail"></param> /// <returns></returns> public static List <Request> getReqsByDonor(string donorEmail) { using (BTProjectEntities db = new BTProjectEntities()) { return(Request.cToDTO(db.request_tbl.Where(r => r.donorEmail.Equals(donorEmail)).ToList())); } }
public static List <Time> getAllTimes() { using (BTProjectEntities db = new BTProjectEntities()) { return(Time.cToDTO(db.time_tbl.ToList())); } }
public static List <Occupation> GetOccupations() { using (BTProjectEntities db = new BTProjectEntities()) { return(Occupation.cToDTO(db.occuption_tbl.ToList())); } }
public static List <Learner> GetLearnesForBookByDonor(int bookId, string donorId) { using (BTProjectEntities db = new BTProjectEntities()) { //get reqs for donor List <Request> allRequests = Request.cToDTO(db.request_tbl.ToList()); allRequests = allRequests.Where(req => req.donorEmail == donorId).ToList(); //generate an id list of the the reqs List <int> ids = allRequests.Select(req => req.reqId).ToList(); //create the original list of all matchings List <Matching> allMatchings = Matching.cToDTO(db.Matching_tbl.AsNoTracking().ToList()); //get all matchings associated with the reqs --- contained in the id list we generated allMatchings = allMatchings.Where(x => ids.Contains(x.reqId)).ToList(); //generate an id list of the the matchings List <int> matchIds = allMatchings.Select(m => m.learnerId).ToList(); //create the original list of all learners List <Learner> allLearners = Learner.cToDTO(db.learners_tbl.ToList()); //get all learners associated with the donor --- contained in the id list we generated allLearners = allLearners.Where(x => matchIds.Contains(x.learnerId)).ToList(); return(allLearners); } }
//הפונקציות הבאות מחשבות כמה לומדים יש כבר לספר מסוים מתוך כמה שצריך. /// <summary> /// ניתן לשלוח את הקוד עצמו /// הפונקציה מקבלת קוד ספר בודד ומחזירה את מספר השיבוצים שלו /// </summary> public static int getCountMatchingsForRequest(int book) { using (BTProjectEntities db = new BTProjectEntities()) { return(db.Matching_tbl.AsNoTracking().Count(x => x.bookId == book)); } }
// public static Matching getMatchByDonorLearnerAndBook(string donorId, int learnerId, int bookId) //{ // List<Matching> matchs = new List<Matching>(); // //מחזיר את ההצעות שעדיין ניתן להרשם אליהם. // return (Offer.cToDTO(db.request_tbl.ToList()).Where(o => (o.registerEndDate) > DateTime.Today)).ToList(); //} public static Matching getMatchByDonorLearnerAndBook(string donorId, int learnerId, int bookId) { using (BTProjectEntities db = new BTProjectEntities()) { List <Matching> matchs = new List <Matching>(); matchs = getAllMatchings(); //filter by book id and learner id matchs = matchs.Where(m => m.learnerId == learnerId && m.bookId == bookId).ToList(); //retreive the req id's //get only the id's for better peformance List <int> ids = matchs.Select(match => match.reqId).ToList(); //create the original list of all requests List <Request> allReqs = Request.cToDTO(db.request_tbl.ToList()); //get all reqs with the right id's---that belong to a certain learner and donor and book List <Request> myresult = allReqs.Where(x => ids.Contains(x.reqId) && x.donorEmail == donorId).ToList(); //there should be onlt one such matching matchs = matchs.Where(ma => ma.reqId == myresult[0].reqId).ToList(); return(matchs[0]); } }
public static List <Request> getAllRequests() { using (BTProjectEntities db = new BTProjectEntities()) { return(Request.cToDTO(db.request_tbl.ToList())); } }
public static List <Matching> getAllMatchings() { using (BTProjectEntities db = new BTProjectEntities()) { return(Matching.cToDTO(db.Matching_tbl.AsNoTracking().ToList())); } }
public static void addLearner(Learner l) { using (BTProjectEntities db = new BTProjectEntities()) { db.learners_tbl.Add(Learner.DTOToc(l)); db.SaveChanges(); } }
//-----------Add----------------------------- public static void addLearning(Matching newMatch) { using (BTProjectEntities db = new BTProjectEntities()) { db.Matching_tbl.Add(DTO.Matching.DTOToc(newMatch)); //db.SaveChanges(); } }
//-----------DELETE--------------------------- public static void deleteLearner(int id) { using (BTProjectEntities db = new BTProjectEntities()) { db.learners_tbl.Remove(db.learners_tbl.Find(id)); db.SaveChanges(); } }
public static List <Offer> getCurrentRequests() { using (BTProjectEntities db = new BTProjectEntities()) { //מחזיר את ההצעות שעדיין ניתן להרשם אליהם. return((Offer.cToDTO(db.request_tbl.ToList()).Where(o => (o.registerEndDate) > DateTime.Today)).ToList()); } }
/// <summary> /// ניתן לשלוח את האוביקט כולו /// הפונקציה מקבלת ספר בודד ומחזירה את מספר השיבוצים שלו /// </summary> public static int getCountMatchingsForRequest(Book book) { using (BTProjectEntities db = new BTProjectEntities()) { int id = db.Book_tbl.FirstOrDefault(b => b.BookId == book.BookId).BookId; return(db.Matching_tbl.AsNoTracking().Count(x => x.bookId == id)); } }
public static List <Book> getBooksByDonor(string donorEmail) { using (BTProjectEntities db = new BTProjectEntities()) { List <Request> reqsResult = Request.cToDTO(db.request_tbl.Where(r => r.donorEmail.Equals(donorEmail)).ToList()); return(getBooksByReqs(reqsResult)); } }
//public static BTProjectEntities db = new BTProjectEntities(); //----------GET--------------------------- public static List <Book> getAllBooks() { using (BTProjectEntities db = new BTProjectEntities()) { List <Book> res = (Book.cToDTO(db.Book_tbl.ToList())); return(res.Where(b => b.BookId != 1).ToList()); } }
///<summary>:return the current learnings per user</summary> public static List <CurrentLearnings> GetCurrentLearnings(int learnerid) { using (BTProjectEntities db = new BTProjectEntities()) { List <Matching_tbl> l = new List <Matching_tbl>(); l = db.Matching_tbl.AsNoTracking().ToList(); List <CurrentLearnings> res = new List <CurrentLearnings>(); l = l.Where(x => x.learnerId == learnerid).ToList(); res = CurrentLearnings.cToDTO(l); //res = CurrentLearnings.cToDTO(l.Whereb(x => x.learnerId == learnerid).ToList()); return(res); } }
//adds a new closed group to the db public static void addGroup(int reqId, string groupName) { using (BTProjectEntities db = new BTProjectEntities()) { ClosedGroup cg = new ClosedGroup(); cg.reqId = reqId; cg.groupName = groupName; List <ClosedGroup> c = new List <ClosedGroup>(); c.Add(cg); db.closedGroup_tbl.Add(ClosedGroup.DTOToc(c)[0]); db.SaveChanges(); } }
public static void addRequest(Request r) { using (BTProjectEntities db = new BTProjectEntities()) { { r.BookId = db.Book_tbl.FirstOrDefault(b => b.BookName == r.BookName).BookId; r.timeId = db.time_tbl.FirstOrDefault(t => t.timeDesc == r.timeDesc).timeId; db.request_tbl.Add(DTO.Request.DTOToc(r)); db.SaveChanges(); } } }
public static List <Book> getBooksByReqs(List <Request> reqs) { using (BTProjectEntities db = new BTProjectEntities()) { //get only the id's for better peformance List <int> ids = reqs.Select(book => book.BookId).ToList(); //create the original list of all books List <Book> allBooks = Book.cToDTO(db.Book_tbl.ToList()); //get all books associated with the reqs --- contained in the id list we generated List <Book> booksResult = allBooks.Where(x => ids.Contains(x.BookId)).ToList(); return(booksResult); } }
/// <summary> /// collect the id's of all the learners that joined to this request. /// </summary> /// <param name="requestId"></param> private static List <int> GetMatchingsPerRequest(int requestId) { using (BTProjectEntities db = new BTProjectEntities()) { var l = Matching.cToDTO(db.Matching_tbl.AsNoTracking().Where(m => m.reqId == requestId).ToList()); var learnerIdList = new List <int>(); foreach (Matching learner in l) { learnerIdList.Add(learner.learnerId); } return(learnerIdList); } }
public static void editDonor(Request d) { using (BTProjectEntities db = new BTProjectEntities()) { //can change donor email List <request_tbl> reqs = db.request_tbl.Where(r => r.donorEmail == d.donorEmail).ToList(); //reqs.ForEach( req => req.donorEmail = d.donorEmail); reqs.ForEach(req => { req.password = d.password; req.donorName = d.donorName; db.Entry(req).State = System.Data.Entity.EntityState.Modified; }); db.SaveChanges(); } }
public static void addDonor(string name, string email) { using (BTProjectEntities db = new BTProjectEntities()) { //יצירת מופע של מחלקת מייל ,עם הנתונים הספציפיים שהתקבלו בפונקציה Email e = new Email(name, email); //קבלת סיסמא רנדומלית,סיסמא זו תשלח לתורם החדש דרך המייל int pass = logic.getRandomPassword(); e.sendEmailViaWebApi(pass.ToString()); //שמירת התורם החדש במסד db.request_tbl.Add(DTO.Request.DTOToc(new Request() { donorEmail = email, donorName = name, password = pass.ToString(), BookId = 1 })); db.SaveChanges(); } }
//public static List<T> getListByRelationship(int id) //{ //} ///<summary>פונקציה לשליפת כל הלומדים לתורם מסויםsummary> ///<param>the id of the relevant donor</param> ///<returns>list of the learners that are connected to this donor</returns> public static List <Learner> GetLearnersByDonor(string donorId) { using (BTProjectEntities db = new BTProjectEntities()) { // calles the function above, but for all the donor's reqeusts. List <Request> allRequests = Request.cToDTO(db.request_tbl.ToList()); allRequests = allRequests.Where(r => r.donorEmail == donorId).ToList(); List <Learner> res = new List <Learner>(); foreach (Request ra in allRequests) { res.AddRange(SingleLearner.GetLearnesForBookByReq(ra.reqId)); } return(res); } }
///<summary>פונקציה לשליפת כל הלומדים של ספר מסוים לתורם מסוים=כל הלומדים מבקשה מסוימת.</summary> ///<param>the id of the relevant request</param> ///<returns>list of the learners that are connected to this request</returns> public static List <Learner> GetLearnesForBookByReq(int requestId) { using (BTProjectEntities db = new BTProjectEntities()) { List <Learner> allLearners = Learner.cToDTO(db.learners_tbl.ToList()); List <int> correntIDs = SingleLearner.GetMatchingsPerRequest(requestId); List <Learner> res = new List <Learner>(); foreach (Learner l in allLearners) { if (correntIDs.Contains(l.learnerId)) { res.Add(l); } } return(res); } }
//לא הולך לי.......... ///// <summary> /////,פונקציה לשליפת כל הבקשות של תורם מסוים ///// </summary> ///// <param name="donorEmail"></param> ///// <returns></returns> //public static List<Request> getRequestsByDonor(string donorEmail) //{ // var r= Request.cToDTO(data.db.request_tbl.Where(r => r.donorEmail.Equals(donorEmail)).ToList()); // var res; // foreach //} /// <summary> ///פונקציה למציאת כל הספרים שלומד מסוים לומד אותם עבור תורם מסוים /// </summary> /// //why does the function get reqId and not donor Id---maybe that is the donor's Id //but it does't make sense because we are trying to find the reqID public static List <Request> SingleLearnerForSingleDonorReqs(int learnerId, string donorId) { using (BTProjectEntities db = new BTProjectEntities()) { //first create a list of matchings thst are associated with the given learner List <Matching> matchRes = new List <Matching>(); matchRes = Matching.cToDTO(db.Matching_tbl.AsNoTracking().Where(m => m.learnerId == learnerId).ToList()); //get only the id's for better peformance List <int> ids = matchRes.Select(match => match.reqId).ToList(); //create the original list of all requests List <Request> allReqs = Request.cToDTO(db.request_tbl.ToList()); //get all reqs with the right id's---that belong to a certain learner and donor List <Request> myresult = allReqs.Where(x => ids.Contains(x.reqId) && x.donorEmail == donorId).ToList(); return(myresult); } }
public static void addLearner(string name, string email) { //יצירת מופע של מחלקת מייל ,עם הנתונים הספציפיים שהתקבלו בפונקציה Email e = new Email(name, email); //קבלת סיסמא רנדומלית,סיסמא זו תשלח ללומד החדש דרך המייל int pass = logic.getRandomPassword(); e.sendEmailViaWebApi(pass.ToString()); //שמירת הלומד החדש במסד //עם הסיסמא הרנדומלית איתה יצטרך להכנס בפעם הבאה ,ואז יוכל גם להחליפה using (BTProjectEntities db = new BTProjectEntities()) { db.learners_tbl.Add(DTO.Learner.DTOToc(new Learner() { learnerName = name, learnerEmail = email, password = pass.ToString() })); db.SaveChanges(); } }
public static void deleteMatch(Matching m, string donorEmail) { //db.Matching_tbl.Remove(Matching.DTOToc(m)); //this is becuse we nee dto mark the object in the context as deleted // ef will afterwards compare the context and find the changes and update as we have marked //we only need to use this way if we generate the object on our own //otherwise we can simply use remove() if retrieved from dbcontext using (BTProjectEntities db = new BTProjectEntities()) { bool oldValidateOnSaveEnabled = db.Configuration.ValidateOnSaveEnabled; try { db.Configuration.ValidateOnSaveEnabled = false; db.Entry(Matching.DTOToc(m)).State = EntityState.Deleted; //db.Matching_tbl.Attach(Matching.DTOToc(m)); db.SaveChanges(); } finally { db.Configuration.ValidateOnSaveEnabled = oldValidateOnSaveEnabled; } } using (BTProjectEntities db = new BTProjectEntities()) { //send emails to learner and donor List <Learner> l = Learner.cToDTO(db.learners_tbl.ToList()); Learner learner = l.FirstOrDefault(le => le.learnerId == m.learnerId); Email e = new Email(); //email donor e.sendEmailViaWebApi("", donorEmail, "ביטול השתתפות לומד בתוכנית לימוד", "C:\\Users\tzipp\\BTProject\\cheshvanProject\\BLL\\BLL\\cancelMatching.rtf", "", "", " הלומד" + learner.learnerName + "מזהה תוכנית הלימוד " + " " + m.reqId); //emailLearner e.sendEmailViaWebApi("", learner.learnerEmail, "ביטול השתתפות בתוכנית לימוד", "C:\\Users\tzipp\\BTProject\\cheshvanProject\\BLL\\BLL\\CancelMatchingLearner.rtf", "", "", "מזהה תוכנית הלימוד" + m.reqId + " מייל היזם:" + donorEmail); } //db.Entry(Matching.DTOToc(m)).State = EntityState.Deleted; //db.SaveChanges(); }
public static List <Offer> getCurrentRequests(Learner learner) { using (BTProjectEntities db = new BTProjectEntities()) { //if the learner is a vulunteer if (learner.groupId != null) { //he can only watch his req //find the req id var group = ClosedGroup.cToDTO(db.closedGroup_tbl.Where(cg => cg.GroupId == learner.groupId).ToList()); var groupReqId = group[0].reqId; return(Offer.cToDTO(db.request_tbl .Where(r => r.reqId == groupReqId && r.RegisterEndDate > DateTime.Today) //ההרשמה עדייין פתוחה .ToList())); } //מחזיר את ההצעות שעדיין ניתן להרשם אליהם. List <Offer> currentLearning = (Offer.cToDTO(db.request_tbl .Where(r => //בדיקה שכל הפרמטרים של הבקשה מתאימים לתנאי הלומד r.genderid == learner.gender && //המין מתאים r.occuptionId == learner.occuptionId && //העיסוק מתאים r.RegisterEndDate > DateTime.Today && //ההרשמה עדייין פתוחה r.reqEndDate <learner.endDate && //זמן הלימוד המבוקש אינו מתארך מעבר למה שהלומד מעונין r.reqStartDate> learner.startDate//זמן הלימוד המבוקש אינו מתחיל לפני התאריך שממנו והלאה הלומד מעונין ללמוד ).ToList())); //if (currentLearning.Count > 0) // return currentLearning; //else // return return(currentLearning); } }
//-----------Edit---------------------------- public static void editLearner(Learner l) { using (BTProjectEntities db = new BTProjectEntities()) { if (l.password != null && l.endDate > DateTime.Today) { List <learners_tbl> learners = db.learners_tbl.Where(r => r.learnerId == l.learnerId).ToList(); learners.ForEach(le => { le.password = l.password; le.learnerName = l.learnerName; le.occuptionId = l.occuptionId; le.startDate = l.startDate; le.endDate = l.endDate; le.gender = l.gender; db.Entry(le).State = System.Data.Entity.EntityState.Modified; }); db.SaveChanges(); } } }