コード例 #1
0
        public void Delete(int id)
        {
            Models.DBObjects.Invoice dbInvoiceModel = dbContext.Invoices.FirstOrDefault(m => m.InvoiceId == id);

            dbContext.Invoices.DeleteOnSubmit(dbInvoiceModel);

            dbContext.SubmitChanges();
        }
コード例 #2
0
        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();
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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();
            }
        }