Exemple #1
0
        public HttpStatusCodeResult ApproveOrRejectEnrollClass(int ClassId, bool IsApproved)
        {
            try
            {
                string            customerUsername  = User.Identity.GetUserName();
                RegistrationClass RegistrationClass = db.RegistrationClasses.Include(s => s.Customer).Include(s => s.Tutor).Include(s => s.Subjects).SingleOrDefault(s => s.Id == ClassId);
                Tutor             tutor             = RegistrationClass.Tutor;
                string            tutorUsername     = UserManager.FindById(tutor.UserId).UserName;
                Customer          customer          = RegistrationClass.Customer;
                if (IsApproved)
                {
                    RegistrationClass.Tutor           = tutor;
                    RegistrationClass.Status          = Enums.ClassStatus.CustomerApproved;
                    RegistrationClass.ReceivedDate    = DateTime.Now;
                    RegistrationClass.IsClosed        = true;
                    db.Entry(RegistrationClass).State = EntityState.Modified;
                    db.SaveChanges();
                    //send to tutor
                    EmailSenderService.SendHtmlFormattedEmail(tutor.Email, "Đã duyệt yêu cầu nhận lớp" + RegistrationClass.Id,
                                                              EmailSenderService.PopulateBodyTutorCustomerApprovedEnrollmentRequestToTutor(customer, tutor, RegistrationClass, "~/EmailTemplates/CustomerApprovedTutorEnrollmenToTutor.html"));

                    //send to admin
                    EmailSenderService.SendHtmlFormattedEmail(AdminEmail, "Yêu cầu gia sư nhận lớp được duyệt",
                                                              EmailSenderService.PopulateBodyTutorCustomerApprovedEnrollmentRequestToAdmin(customer, customerUsername, tutor, tutorUsername, RegistrationClass.Id.ToString(), "~/EmailTemplates/CustomerApprovedTutorEnrollmentToAdmin.html"));
                }
                else
                {
                    RegistrationClass.Status          = Enums.ClassStatus.CustomerRejected;
                    db.Entry(RegistrationClass).State = EntityState.Modified;
                    db.SaveChanges();
                    //send to tutor
                    EmailSenderService.SendHtmlFormattedEmail(tutor.Email, "Từ chối yêu cầu nhận lớp mã số : " + RegistrationClass.Id,
                                                              EmailSenderService.PopulateBody(customer.FullName, tutor.FullName, RegistrationClass.Id.ToString(), "~/EmailTemplates/CustomerRejectedTutorEnrollmentToTutor.html"));
                }
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError));
            }
            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }