public void Delete(int id) { Models.DBObjects.Invoice dbInvoiceModel = dbContext.Invoices.FirstOrDefault(m => m.InvoiceId == id); dbContext.Invoices.DeleteOnSubmit(dbInvoiceModel); dbContext.SubmitChanges(); }
public void Update(InvoiceModel invoiceModel) { Models.DBObjects.Invoice dbInvoiceModel = dbContext.Invoices.FirstOrDefault(m => m.InvoiceId == invoiceModel.InvoiceId); if (invoiceModel != null) { dbInvoiceModel.InvoiceId = invoiceModel.InvoiceId; dbInvoiceModel.Invoice_Series = invoiceModel.Invoice_Series; dbInvoiceModel.Create_Date = invoiceModel.Create_Date; dbInvoiceModel.Contractor = invoiceModel.Contractor; dbInvoiceModel.StudentId = invoiceModel.StudentId; dbInvoiceModel.Quantity = invoiceModel.Quantity; dbInvoiceModel.StudentCourse = invoiceModel.StudentCourse; dbInvoiceModel.StudentPrice = invoiceModel.StudentPrice; dbContext.SubmitChanges(); } }
public InvoiceModel GetInvoiceById(int id) { Models.DBObjects.Invoice dbInvoiceModel = dbContext.Invoices.FirstOrDefault(m => m.InvoiceId == id); InvoiceModel invoiceModel = new InvoiceModel(); if (dbInvoiceModel != null) { invoiceModel.InvoiceId = dbInvoiceModel.InvoiceId; invoiceModel.Invoice_Series = dbInvoiceModel.Invoice_Series; invoiceModel.Create_Date = dbInvoiceModel.Create_Date; invoiceModel.Contractor = dbInvoiceModel.Contractor; invoiceModel.StudentId = dbInvoiceModel.StudentId; invoiceModel.Quantity = dbInvoiceModel.Quantity; invoiceModel.StudentCourse = dbInvoiceModel.StudentCourse; invoiceModel.StudentPrice = dbInvoiceModel.StudentPrice; } return(invoiceModel); }
public void Insert(InvoiceModel invoiceModel) { if (invoiceModel != null) { Models.DBObjects.Invoice dbInvoiceModel = new Models.DBObjects.Invoice(); dbInvoiceModel.InvoiceId = invoiceModel.InvoiceId; dbInvoiceModel.Invoice_Series = invoiceModel.Invoice_Series; dbInvoiceModel.Create_Date = invoiceModel.Create_Date; dbInvoiceModel.Contractor = invoiceModel.Contractor; dbInvoiceModel.StudentId = invoiceModel.StudentId; dbInvoiceModel.Quantity = invoiceModel.Quantity; List <StudentModel> students = studentRepository.GetAllStudents(); foreach (StudentModel student in students) { if (dbInvoiceModel.StudentId == student.StudentId) { List <TeacherWithCourseNameViewModel> teachers = teacherRepository.GetAllTeachersWithCourseNames(); foreach (TeacherWithCourseNameViewModel teacher in teachers) { if (student.TeacherId == teacher.TeacherId) { dbInvoiceModel.StudentCourse = teacher.CourseName; List <CourseModel> courses = courseRepository.GetAllCourses(); foreach (CourseModel course in courses) { if (dbInvoiceModel.StudentCourse == course.Name) { dbInvoiceModel.StudentPrice = course.Price; } } } } } } dbContext.Invoices.InsertOnSubmit(dbInvoiceModel); dbContext.SubmitChanges(); } }