// POST api/<controller> public void Post([FromBody] StudentInLesson s) { try { s.insertStudent(); } catch (Exception ex) { throw new Exception("Error to save student" + ex); } }
public static StudentInLessonDTO ConvertToDTO(StudentInLesson studentInLesson) { StudentInLessonDTO studentInLessonDTO = new StudentInLessonDTO(); studentInLessonDTO.Id = studentInLesson.Id; studentInLessonDTO.StudentId = studentInLesson.StudentId; studentInLessonDTO.LessonId = studentInLesson.LessonId; studentInLessonDTO.StartDate = studentInLesson.StartDate; studentInLessonDTO.FinishDate = studentInLesson.FinishDate; return(studentInLessonDTO); }
public void Delete(int lessCode) { try { StudentInLesson s = new StudentInLesson(); s.DeleteAllStudent(lessCode); } catch (Exception) { throw; } }
// DELETE api/<controller>/5 public void Delete(string studentId, int lessonCode) { try { StudentInLesson s = new StudentInLesson(); s.LogOutLesson(studentId, lessonCode); } catch (Exception) { throw; } }
public void put(List <StudentInLesson> students) { try { StudentInLesson s = new StudentInLesson(); s.insertStudentTemp(students); } catch (Exception ex) { throw new Exception("Error to save student" + ex); } }
public static StudentInLessonDTO ConvertToDTO(StudentInLesson studentInLesson) { StudentInLessonDTO studentInLessonDTO = new StudentInLessonDTO(); studentInLessonDTO.Id = studentInLesson.Id; studentInLessonDTO.StudentId = studentInLesson.StudentId; studentInLessonDTO.LessonId = studentInLesson.LessonId; studentInLessonDTO.Date = studentInLesson.Date.ToString(); studentInLessonDTO.Attendance = studentInLesson.Attendance; studentInLessonDTO.WeekId = studentInLesson.WeekId; return(studentInLessonDTO); }
// GET api/<controller>/5 public List <StudentInLesson> Get(string id) { try { List <StudentInLesson> si = new List <StudentInLesson>(); StudentInLesson s = new StudentInLesson(); si = s.GetMyCourses(id); return(si); } catch (Exception ex) { throw new Exception("Error to save student in file" + ex); } }
public static StudentInLesson ConvertFromDTO(StudentInLessonDTO studentInLessonDTO) { StudentInLesson studentInLesson = new StudentInLesson(); if (studentInLessonDTO.Id != default) { studentInLesson.Id = studentInLessonDTO.Id; } studentInLesson.StudentId = studentInLessonDTO.StudentId; studentInLesson.LessonId = studentInLessonDTO.LessonId; studentInLesson.Date = Convert.ToDateTime(studentInLessonDTO.Date); studentInLesson.Attendance = studentInLessonDTO.Attendance; studentInLesson.WeekId = studentInLessonDTO.WeekId; return(studentInLesson); }
public List <StudentInLesson> Get(int lessonId, int courseId) { try { List <StudentInLesson> si = new List <StudentInLesson>(); StudentInLesson s = new StudentInLesson(); si = s.saveAllStudent(lessonId, courseId); return(si); } catch (Exception ex) { throw new Exception("Error to save student in file" + ex); } }
public static bool PostStudentInLessons(LessonDTO lessonDTO, int studentId, string date) { try { using (Gymnastics_Studio_DataEntities GSDE = new Gymnastics_Studio_DataEntities()) { DateTime Date = Convert.ToDateTime(date); StudentInSubscription studentInSubscription = new StudentInSubscription(); studentInSubscription = GSDE.StudentInSubscriptions.Where(x => x.StudentId == studentId && x.StartDate <= Date && x.FinishDate >= Date).FirstOrDefault(); List <StudentInLesson> studentInLessonList = new List <StudentInLesson>(); studentInLessonList = GSDE.StudentInLessons.Where(x => x.StudentInSubscriptionId == studentInSubscription.Id).ToList(); StudentInLesson studentInLesson1 = studentInLessonList[0]; var lastLessonDay = GSDE.Lessons.Where(x => x.Id == studentInLesson1.LessonId).FirstOrDefault().Day; double reminder = ConvertHebrewDayNameToNumber(lessonDTO.Day); reminder -= ConvertHebrewDayNameToNumber(lastLessonDay); if (Convert.ToDateTime(studentInLesson1.Date).AddDays(reminder) < studentInSubscription.StartDate) { reminder += 7; } for (int i = 0; i < studentInLessonList.Count(); i++) { var studentInLesson = studentInLessonList[i]; if (studentInLesson.Date >= Date && Convert.ToDateTime(studentInLesson.Date).AddDays(reminder) >= Date) { studentInLesson.Date = Convert.ToDateTime(studentInLesson.Date).AddDays(reminder); studentInLesson.LessonId = lessonDTO.Id; //Week week = new Week(); //DateTime Date2 = Date.AddDays(7); //week = GSDE.Weeks.Where(x => x.Date <= Date && x.Date > Date2).FirstOrDefault(); //if (week == default) return false; //studentInLesson.WeekId = week.Id; GSDE.SaveChanges(); } } return(true); } } catch (Exception e) { throw e; } }
public static bool UpdateAttendence(int studentInLessonId, bool attendance) { try { using (Gymnastics_Studio_DataEntities GSDE = new Gymnastics_Studio_DataEntities()) { StudentInLesson studentInLesson = new StudentInLesson(); studentInLesson = GSDE.StudentInLessons.Where(x => x.Id == studentInLessonId).FirstOrDefault(); if (studentInLesson == default) { return(false); } studentInLesson.Attendance = attendance; GSDE.SaveChanges(); return(true); } } catch (Exception e) { throw (e); } }
public static ExceptionsEnum CreateLessonList(int StudentId, int LessonId, int StudentInSubscreptionId) { try { using (Gymnastics_Studio_DataEntities GSDE = new Gymnastics_Studio_DataEntities()) { // בדיקה אם לתלמידה מספר שיעורים באותו שבוע נמוך ממספר השיעורים שאמור להיות במנוי StudentInSubscription studentInSubscription = new StudentInSubscription(); studentInSubscription = GSDE.StudentInSubscriptions.Where(x => x.Id == StudentInSubscreptionId).FirstOrDefault(); if (studentInSubscription == default) { return(ExceptionsEnum.StudetInSubscriptionUndefine); } Subscription subscription = new Subscription(); subscription = GSDE.Subscriptions.Where(x => x.Id == studentInSubscription.SubscribtionId).FirstOrDefault(); if (subscription == default) { return(ExceptionsEnum.SubscriptionUndefine); } List <StudentInLesson> studentInLessonList = new List <StudentInLesson>(); studentInLessonList = GSDE.StudentInLessons.Where(x => x.StudentInSubscriptionId == StudentInSubscreptionId).ToList(); studentInLessonList = studentInLessonList.Where(x => x.Date >= studentInLessonList[0].Date && x.Date < ((DateTime)studentInLessonList[0].Date).AddDays(7)).ToList(); //אם לא החזרת שגיאה מתאימה אחרי יצירת enum if (studentInLessonList.Count >= subscription.DaysInWeekNum) { return(ExceptionsEnum.LessonsNumException); } //אם כן לולאה כמס השבועות במנוי ליצירת שיעור כולל טיפול בתשלום וביצירת שבועות WeekFunction.AddWeeksUpTo((DateTime)studentInSubscription.FinishDate); Lesson lesson = new Lesson(); lesson = GSDE.Lessons.Where(x => x.Id == LessonId).FirstOrDefault(); if (lesson == default) { return(ExceptionsEnum.LessonUndefine); } if (studentInSubscription.StartDate == default) { return(ExceptionsEnum.StartDateOfStudentInSubscriptionUndefine); } DateTime SundayDate = ((DateTime)studentInSubscription.StartDate).AddDays(0 - (int)((DateTime)studentInSubscription.StartDate).DayOfWeek); int d = ConvertHebrewDayNameToNumber(lesson.Day) - (int)SundayDate.DayOfWeek; DateTime Date = SundayDate.AddDays(d); if (Date < studentInSubscription.StartDate) { Date = Date.AddDays(7); } for (int i = 0; i < subscription.WeeksNum; i++, Date = Date.AddDays(7)) { StudentInLesson studentInLesson = new StudentInLesson(); studentInLesson.Attendance = true; studentInLesson.Date = Date; studentInLesson.LessonId = LessonId; studentInLesson.StudentId = StudentId; studentInLesson.StudentInSubscriptionId = StudentInSubscreptionId; Week week = new Week(); DateTime Date2 = Date.AddDays(-7); week = GSDE.Weeks.Where(y => y.Date <= Date && y.Date > Date2).FirstOrDefault(); if (week == default) { return(ExceptionsEnum.WeekUndefine); } studentInLesson.WeekId = week.Id; // var x=paymentOfLessson(studentInLesson, subscription, StudentId); // if (x != ExceptionsEnum.True) // return x; int lessonPayment = (int)(subscription.Price / (subscription.WeeksNum * subscription.DaysInWeekNum)); Student student = GSDE.Students.Where(x => x.Id == StudentId).FirstOrDefault(); if (student == default) { return(ExceptionsEnum.StudentUndefine); } student.Balance -= lessonPayment; GSDE.SaveChanges(); while (lessonPayment > 0) { Payment payment = GSDE.Payments.Where(x => x.StudentId == StudentId && x.FinishDate == null).ToList().OrderBy(o => o.StartDate).FirstOrDefault(); switch (payment) { case null: payment = new Payment(); payment.StartDate = DateTime.Now; payment.StudentId = StudentId; payment.Sum = 0 - lessonPayment; payment.FormOfPayment = "חוב"; payment.Balance = 0 - lessonPayment; GSDE.Payments.Add(payment); GSDE.SaveChanges(); payment = GSDE.Payments.Where(x => x.StudentId == StudentId && x.FinishDate == default).FirstOrDefault(); studentInLesson.PaymentId = payment.Id; break; default: if (payment.Balance > 0 && payment.Balance < lessonPayment) { lessonPayment = (int)(lessonPayment - payment.Balance); payment.Balance = 0; payment.FinishDate = DateTime.Now; GSDE.SaveChanges(); } else { payment.Balance = payment.Balance - lessonPayment; lessonPayment = 0; GSDE.SaveChanges(); studentInLesson.PaymentId = payment.Id; GSDE.SaveChanges(); } break; } } GSDE.StudentInLessons.Add(studentInLesson); GSDE.SaveChanges(); } } return(ExceptionsEnum.True); } catch (Exception e) { throw (e); } }
public static ExceptionsEnum CreateLessonListBySubscriptionIdLessonIdStudentInSubscriptionId(int StudentId, int LessonId, DateTime FromDate, int SubscreptionId, int StudentInSubscreptionId) { try { using (Gymnastics_Studio_DataEntities GSDE = new Gymnastics_Studio_DataEntities()) { Lesson lesson = new Lesson(); lesson = GSDE.Lessons.Where(x => x.Id == LessonId).FirstOrDefault(); if (lesson == default) { return(ExceptionsEnum.LessonUndefine); } if (FromDate == default) { return(ExceptionsEnum.FromDateUndefine); } DateTime SundayDate = FromDate.AddDays(0 - (int)FromDate.DayOfWeek); int d = ConvertHebrewDayNameToNumber(lesson.Day) - (int)SundayDate.DayOfWeek; DateTime Date = SundayDate.AddDays(d); if (Date < FromDate) { Date = Date.AddDays(7); } Subscription subscription = new Subscription(); subscription = GSDE.Subscriptions.Where(x => x.Id == SubscreptionId).FirstOrDefault(); if (subscription == default) { return(ExceptionsEnum.SubscriptionUndefine); } for (int i = 0; i < subscription.WeeksNum; i++, Date = Date.AddDays(7)) { StudentInLesson studentInLesson = new StudentInLesson(); studentInLesson.Attendance = true; studentInLesson.Date = Date; studentInLesson.LessonId = LessonId; studentInLesson.StudentId = StudentId; studentInLesson.StudentInSubscriptionId = StudentInSubscreptionId; Week week = new Week(); DateTime Date2 = Date.AddDays(-7); week = GSDE.Weeks.Where(x => x.Date <= Date && x.Date > Date2).FirstOrDefault(); if (week == default) { return(ExceptionsEnum.WeekUndefine); } studentInLesson.WeekId = week.Id; //טיפול בתשלום השיעור // var l=paymentOfLessson(studentInLesson, subscription, StudentId); int lessonPayment = (int)(subscription.Price / (subscription.WeeksNum * subscription.DaysInWeekNum)); Student student = GSDE.Students.Where(x => x.Id == StudentId).FirstOrDefault(); if (student == default) { return(ExceptionsEnum.StudentUndefine); } student.Balance -= lessonPayment; GSDE.SaveChanges(); while (lessonPayment > 0) { Payment payment = GSDE.Payments.Where(x => x.StudentId == StudentId && x.FinishDate == null).ToList().OrderBy(o => o.StartDate).FirstOrDefault(); switch (payment) { case null: payment = new Payment(); payment.StartDate = DateTime.Now; payment.StudentId = StudentId; payment.Sum = 0 - lessonPayment; payment.FormOfPayment = "חוב"; payment.Balance = 0 - lessonPayment; GSDE.Payments.Add(payment); GSDE.SaveChanges(); payment = GSDE.Payments.Where(x => x.StudentId == StudentId && x.FinishDate == default).FirstOrDefault(); studentInLesson.PaymentId = payment.Id; break; default: if (payment.Balance > 0 && payment.Balance < lessonPayment) { lessonPayment = (int)(lessonPayment - payment.Balance); payment.Balance = 0; payment.FinishDate = DateTime.Now; GSDE.SaveChanges(); } else { payment.Balance = payment.Balance - lessonPayment; lessonPayment = 0; GSDE.SaveChanges(); studentInLesson.PaymentId = payment.Id; GSDE.SaveChanges(); } break; } GSDE.StudentInLessons.Add(studentInLesson); GSDE.SaveChanges(); // if (l != ExceptionsEnum.True) // return l; } } return(ExceptionsEnum.True); } } catch (Exception e) { throw (e); } }
//תשלום לשיעור public static ExceptionsEnum paymentOfLessson(StudentInLesson studentInLesson, Subscription subscription, int studentId) { try { using (Gymnastics_Studio_DataEntities GSDE = new Gymnastics_Studio_DataEntities()) { int lessonPayment = (int)(subscription.Price / (subscription.WeeksNum * subscription.DaysInWeekNum)); Student student = GSDE.Students.Where(x => x.Id == studentId).FirstOrDefault(); if (student == default) { return(ExceptionsEnum.StudentUndefine); } student.Balance -= lessonPayment; GSDE.SaveChanges(); while (lessonPayment > 0) { Payment payment = GSDE.Payments.Where(x => x.StudentId == studentId && x.FinishDate == null).ToList().OrderBy(o => o.StartDate).FirstOrDefault(); switch (payment) { case null: payment = new Payment(); payment.StartDate = DateTime.Now; payment.StudentId = studentId; payment.Sum = 0 - lessonPayment; payment.FormOfPayment = "חוב"; payment.Balance = 0 - lessonPayment; GSDE.Payments.Add(payment); GSDE.SaveChanges(); payment = GSDE.Payments.Where(x => x.StudentId == studentId && x.FinishDate == default).FirstOrDefault(); studentInLesson.PaymentId = payment.Id; break; default: if (payment.Balance > 0 && payment.Balance < lessonPayment) { lessonPayment = (int)(lessonPayment - payment.Balance); payment.Balance = 0; payment.FinishDate = DateTime.Now; GSDE.SaveChanges(); } else { payment.Balance = payment.Balance - lessonPayment; lessonPayment = 0; GSDE.SaveChanges(); studentInLesson.PaymentId = payment.Id; GSDE.SaveChanges(); } break; } GSDE.StudentInLessons.Add(studentInLesson); GSDE.SaveChanges(); } } return(ExceptionsEnum.True); } catch (Exception e) { throw (e); } }
public static bool AddStudentInSubscriptionUpToNow(int studentId) { try { using (Gymnastics_Studio_DataEntities GSDE = new Gymnastics_Studio_DataEntities()) { StudentInSubscription studentInSubscription = new StudentInSubscription(); var i = GSDE.StudentInSubscriptions.Where(x => x.StudentId == studentId && x.FinishDate <= DateTime.Now).Max(t => t.StartDate); if (i == default) { return(false); } studentInSubscription = GSDE.StudentInSubscriptions.Where(x => x.StudentId == studentId && x.StartDate == i).First(); WeekFunction.AddWeeksUpTo(DateTime.Now); // הוספת מנוי לתלמידה עד לתאריך נוכחי אלא אם עצרה מנוי או קבעה מנויי אחר DateTime StartDate = (DateTime)studentInSubscription.FinishDate; Subscription Subscription = new Subscription(); Subscription = GSDE.Subscriptions.Where(x => x.Id == studentInSubscription.SubscribtionId).FirstOrDefault(); var n = (double)((int)Subscription.WeeksNum * 7); DateTime FinishDate = StartDate.AddDays(n); while (studentInSubscription.Stop == false && studentInSubscription.FinishDate <= DateTime.Now && (GSDE.StudentInSubscriptions.Where(x => x.StudentId == studentInSubscription.StudentId && ((x.StartDate <= StartDate && x.FinishDate > StartDate) || (x.StartDate > StartDate && x.StartDate < FinishDate))) .FirstOrDefault() == default)) { StudentInSubscription newStudentInSubscription = new StudentInSubscription(); newStudentInSubscription.StudentId = studentId; newStudentInSubscription.SubscribtionId = studentInSubscription.SubscribtionId; newStudentInSubscription.StartDate = studentInSubscription.FinishDate; Subscription subscription = new Subscription(); subscription = GSDE.Subscriptions.Where(x => x.Id == newStudentInSubscription.StudentId).First(); newStudentInSubscription.FinishDate = ((DateTime)newStudentInSubscription.StartDate).AddDays((double)(7 * (int)subscription.WeeksNum)); newStudentInSubscription.Stop = false; GSDE.StudentInSubscriptions.Add(newStudentInSubscription); GSDE.SaveChanges(); newStudentInSubscription = GSDE.StudentInSubscriptions.OrderByDescending(o => o.Id).FirstOrDefault(); //הוספת שיעורים לתלמידה עד לתאריך נוכחי List <StudentInLesson> studentInLessonList = new List <StudentInLesson>(); studentInLessonList = GSDE.StudentInLessons.Where(x => x.StudentInSubscriptionId == studentInSubscription.Id).ToList() .OrderByDescending(o => o.Date).Take((int)subscription.DaysInWeekNum).ToList(); foreach (StudentInLesson studentInLesson in studentInLessonList) { for (int j = 0; j < subscription.WeeksNum; j++) { StudentInLesson newStudentInLessson = new StudentInLesson(); newStudentInLessson.StudentId = studentId; newStudentInLessson.LessonId = studentInLesson.LessonId; newStudentInLessson.Attendance = true; newStudentInLessson.Date = ((DateTime)studentInLesson.Date).AddDays(7 * (j + 1)); newStudentInLessson.StudentInSubscriptionId = newStudentInSubscription.Id; var date2 = ((DateTime)newStudentInLessson.Date).AddDays(-7); newStudentInLessson.WeekId = GSDE.Weeks .Where(x => x.Date <= newStudentInLessson.Date && x.Date >= date2).First().Id; Student student = new Student(); student = GSDE.Students.Where(x => x.Id == studentId).First(); //טיפול בתשלום השיעור Payment payment = new Payment(); int lessonPayment = (int)(subscription.Price / (subscription.WeeksNum * subscription.DaysInWeekNum)); student.Balance -= lessonPayment; while (lessonPayment > 0) { payment = GSDE.Payments.Where(x => x.StudentId == studentId && x.FinishDate == default).ToList().OrderBy(o => o.StartDate).FirstOrDefault(); switch (payment) { case null: payment = new Payment(); payment.StartDate = DateTime.Now; payment.StudentId = studentId; payment.Sum = 0 - lessonPayment; payment.FormOfPayment = "חוב"; payment.Balance = 0 - lessonPayment; GSDE.Payments.Add(payment); GSDE.SaveChanges(); payment = GSDE.Payments.Where(x => x.StudentId == studentId && x.FinishDate == default).FirstOrDefault(); newStudentInLessson.PaymentId = payment.Id; break; default: if (payment.Balance > 0 && payment.Balance < lessonPayment) { lessonPayment = (int)(lessonPayment - payment.Balance); payment.Balance = 0; payment.FinishDate = DateTime.Now; GSDE.SaveChanges(); } else { payment.Balance = payment.Balance - lessonPayment; lessonPayment = 0; GSDE.SaveChanges(); newStudentInLessson.PaymentId = payment.Id; } break; } } studentInSubscription = newStudentInSubscription; StartDate = (DateTime)studentInSubscription.FinishDate; n = (double)((int)Subscription.WeeksNum * 7); FinishDate = StartDate.AddDays(n); GSDE.StudentInLessons.Add(newStudentInLessson); GSDE.SaveChanges(); } } } return(true); } } catch (Exception e) { throw (e); } }