public static void addLearner(Learner l) { using (BTProjectEntities db = new BTProjectEntities()) { db.learners_tbl.Add(Learner.DTOToc(l)); 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(); } }
//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 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 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(); }
//-----------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(); } } }