Exemplo n.º 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));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        public JsonResult ActivateCustomer(int CustomerId)
        {
            try
            {
                Customer customer = db.Customers.SingleOrDefault(s => s.Id == CustomerId);
                if (!customer.IsActivate)
                {
                    customer.IsActivate = true;
                }
                db.Entry(customer).State = EntityState.Modified;
                db.SaveChanges();
                EmailSenderService.SendHtmlFormattedEmail(customer.Email, "Kích hoạt tài khoản", EmailSenderService.PopulateBody(customer.FullName, "~/EmailTemplates/ActivateAccountSuccess.html"));
            }
            catch (Exception ex)
            {
                return(Json(new { Status = "Error" }));
            }

            return(Json(new { Status = "OK" }));
        }
Exemplo n.º 4
0
        public JsonResult DisableTutor(int TutorId)
        {
            try
            {
                Tutor tutor = db.Tutors.SingleOrDefault(s => s.Id == TutorId);
                if (!tutor.IsEnable)
                {
                    tutor.IsEnable = true;
                    EmailSenderService.SendHtmlFormattedEmail(tutor.Email, "Mở tài khoản", EmailSenderService.PopulateBody(tutor.FullName, "~/EmailTemplates/EnableAccountNotification.html"));
                }
                else
                {
                    tutor.IsEnable = false;
                    EmailSenderService.SendHtmlFormattedEmail(tutor.Email, "Khóa tài khoản", EmailSenderService.PopulateBody(tutor.FullName, "~/EmailTemplates/DisableAccountNotification.html"));
                }
                db.Entry(tutor).State = EntityState.Modified;
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                return(Json(new { Status = "Error" }));
            }

            return(Json(new { Status = "OK" }));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> RegisterTutor(HttpPostedFileBase Avatar, PrivateTutorOnline.Models.BindingModels.TutorBindingModel tutorInfo)
        {
            var user = new ApplicationUser {
                UserName = tutorInfo.Username, Email = tutorInfo.Email, PhoneNumber = tutorInfo.PhoneNumber
            };
            var result = UserManager.Create(user, tutorInfo.Password);

            if (result.Succeeded)
            {
                UserManager.AddToRole(user.Id, "Tutor");
                //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                Tutor tutor = new Tutor();
                tutor.UserId    = user.Id;
                tutor.FullName  = tutorInfo.FullName;
                tutor.City      = tutorInfo.City;
                tutor.District  = tutorInfo.District;
                tutor.Ward      = tutorInfo.Ward;
                tutor.Street    = tutorInfo.Street;
                tutor.Advantage = tutorInfo.Advantage;
                if (tutorInfo.DateOfBirth.HasValue)
                {
                    tutor.DateOfBirth = tutorInfo.DateOfBirth.Value;
                }
                tutor.Gender         = tutorInfo.Gender;
                tutor.Degree         = tutorInfo.Degree;
                tutor.Email          = tutorInfo.Email;
                tutor.GraduationYear = tutorInfo.GraduationYear;
                tutor.HomeTown       = tutorInfo.HomeTown;
                tutor.IdentityNumber = tutorInfo.IdentityNumber;
                tutor.MajorSubject   = tutorInfo.MajorSubject;
                tutor.PhoneNumber    = tutorInfo.PhoneNumber;
                tutor.University     = tutorInfo.UniversityName;
                if (Avatar != null && Avatar.ContentLength > 0)
                {
                    tutor.Image = new byte[Avatar.ContentLength];
                    Avatar.InputStream.Read(tutor.Image, 0, Avatar.ContentLength);
                }
                tutor.Subjects = new List <Subject>();
                tutor.Grades   = new List <Grade>();
                foreach (int i in tutorInfo.Subjects)
                {
                    tutor.Subjects.Add(context.Subjects.SingleOrDefault(s => s.Id == i));
                }
                foreach (int i in tutorInfo.Grades)
                {
                    tutor.Grades.Add(context.Grades.SingleOrDefault(gr => gr.Id == i));
                }
                tutor.IsActivate = false;
                tutor.IsEnable   = true;
                context.Tutors.Add(tutor);
                context.SaveChanges();
                try
                {
                    //send to tutor
                    EmailSenderService.SendHtmlFormattedEmail(tutorInfo.Email, "Đăng kí tài khoản", EmailSenderService.PopulateBody(tutorInfo.FullName, tutorInfo.Username, "~/EmailTemplates/AccountRegisterSuccess.html"));
                    //send to admin
                    EmailSenderService.SendHtmlFormattedEmail(AdminEmail, "Gia sư đăng kí tài khoản", EmailSenderService.PopulateBody(tutorInfo.FullName, tutorInfo.Username, "~/EmailTemplates/AccountRegisterAdminNotification.html"));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", "Tài khoản của bạn đã được tạo thành công ! Vui lòng kiểm tra Email ");
                    return(RedirectToAction("Login", "Account"));
                }

                ModelState.AddModelError("", "Tài khoản của bạn đã được tạo thành công ! Vui lòng kiểm tra Email ");
                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                return(RedirectToAction("TutorRegistrationForm", "Tutors"));
            }
        }
Exemplo n.º 6
0
        public async Task <ActionResult> RegisterCustomer(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Username, Email = model.Email, PhoneNumber = model.PhoneNumber
                };
                var result = UserManager.Create(user, model.Password);
                if (result.Succeeded)
                {
                    context.Customers.Add(new Customer()
                    {
                        UserId      = user.Id,
                        FullName    = model.FullName,
                        PhoneNumber = model.PhoneNumber,
                        Email       = model.Email,
                        City        = model.City,
                        District    = model.District,
                        Street      = model.Street,
                        Ward        = model.Ward,
                        IsActivate  = false,
                        IsEnable    = true
                    });
                    await context.SaveChangesAsync();

                    UserManager.AddToRole(user.Id, "Customer");
                    try
                    {
                        //send to customer
                        EmailSenderService.SendHtmlFormattedEmail(model.Email, "Đăng kí tài khoản", EmailSenderService.PopulateBody(model.FullName, model.Username, "~/EmailTemplates/AccountRegisterSuccess.html"));
                        //send to admin
                        EmailSenderService.SendHtmlFormattedEmail(AdminEmail, "Phụ huynh đăng kí tài khoản", EmailSenderService.PopulateBody(model.FullName, model.Username, "~/EmailTemplates/AccountRegisterAdminNotification.html"));
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", "Tài khoản của bạn đã được tạo thành công ! Vui lòng kiểm tra Email ");
                        return(RedirectToAction("Login", "Account"));
                    }
                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    ModelState.AddModelError("", "Tài khoản của bạn đã được tạo thành công ! Vui lòng kiểm tra Email ");
                    return(RedirectToAction("Login", "Account"));
                }
                else
                {
                    return(RedirectToAction("Register", "Account"));
                }
            }

            // If we got this far, something failed, redisplay form
            return(RedirectToAction("Register", "Account"));
        }