예제 #1
0
        public HttpStatusCodeResult ReceiveClass(int ClassId)
        {
            try
            {
                string            tutorUsername     = User.Identity.GetUserName();
                string            UserId            = User.Identity.GetUserId();
                RegistrationClass RegistrationClass = db.RegistrationClasses.Include(s => s.Customer).SingleOrDefault(s => s.Id == ClassId);
                Customer          customer          = RegistrationClass.Customer;
                string            customerUsername  = UserManager.FindById(customer.UserId).UserName;
                Tutor             tutor             = db.Tutors.SingleOrDefault(s => s.UserId == UserId);
                RegistrationClass.Tutor  = tutor;
                RegistrationClass.Status = Enums.ClassStatus.WaitingForCustomerApproval;

                db.Entry(RegistrationClass).State = EntityState.Modified;
                db.SaveChanges();
                //send to tutor
                EmailSenderService.SendHtmlFormattedEmail(tutor.Email, "Yêu cầu nhận lớp mã số : " + RegistrationClass.Id,
                                                          EmailSenderService.PopulateBody(customer.FullName, tutor.FullName, RegistrationClass.Id.ToString(), "~/EmailTemplates/ClassTutorEnrollmentNotificationToTutor.html"));
                //send to customer
                EmailSenderService.SendHtmlFormattedEmail(customer.Email, "Yêu cầu nhận lớp",
                                                          EmailSenderService.PopulateBodyTutorEnrollClassNotificationToCustomer(customer.FullName, tutor, RegistrationClass.Id.ToString(), "~/EmailTemplates/ClassTutorEnrollmentNotificationToCustomer.html"));
                //send to admin
                EmailSenderService.SendHtmlFormattedEmail(AdminEmail, "Gia sư đăng kí nhận lớp",
                                                          EmailSenderService.PopulateBodyTutorEnrollClassNotificationToAdmin(customer, customerUsername, tutor, tutorUsername, RegistrationClass.Id.ToString(), "~/EmailTemplates/ClassTutorEnrollmentNotificationToAdmin.html"));
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }