public ActionResult StudentFeedback(StudentFeedbackViewModel viewModel) { var student = _studentService.GetStudentById(User.Identity.GetUserId()); ViewBag.BranchId = student.BranchId; var studetnName = _studentService.GetStudentById(User.Identity.GetUserId()); var name = studetnName.FirstName + " " + studetnName.MiddleName + " " + studetnName.LastName; if (ModelState.IsValid) { var result = _studentFeedbackService.Save(new StudentFeedback { Name = name, Email = viewModel.Email, Contact = viewModel.Contact, Message = viewModel.Message, UserId = viewModel.UserId, Status = "Waiting", Rating = viewModel.Rating }); if (result.Success) { var bodySubject = "Student Feedback"; string body = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/MailDesign/CommonMailDesign.html"))) { body = reader.ReadToEnd(); } body = body.Replace("{BranchName}", studetnName.BranchName); body = body.Replace("{ModuleName}", "Student : " + name + "<br/>" + "Feedback:" + viewModel.Message + "<br/>"); body = body.Replace("{BranchAdminEmail}", viewModel.Email); var emailMessage = new MailModel { From = viewModel.Email, Body = body, Subject = bodySubject, To = ConfigurationManager.AppSettings[Common.Constants.AdminEmail] }; _emailService.Send(emailMessage); Success(result.Results.FirstOrDefault().Message); ModelState.Clear(); viewModel = new StudentFeedbackViewModel(); } else { _logger.Warn(result.Results.FirstOrDefault().Message); Warning(result.Results.FirstOrDefault().Message, true); } } viewModel.Name = name; return(View(viewModel)); }
public ActionResult Student(long id) { var year = DateTime.Now.Year; var viewmodel = new StudentFeedbackViewModel(); viewmodel.studentid = id; var student = repository.GetUser(id); if (student == null) { return(SendJsonErrorResponse("Feedback: Student not found")); } viewmodel.studentname = student.ToName(); var allocated = student.classes_students_allocateds.FirstOrDefault(x => x.year == year); int?studentschool = null; IQueryable <SelectListItem> teachers = null; if (allocated != null) { studentschool = allocated.school_class.schoolid; // get teachers var classesAttending = student.classes_students_allocateds.Where(x => x.year == year).Select(x => x.classid).ToArray(); var matches = repository.GetUsers().Where(x => x.usergroup == (int)UserGroup.TEACHER) .SelectMany(x => x.classes_teachers_allocateds) .Where(z => z.year == year && classesAttending.Contains(z.classid) && z.user.email != null && z.user.email != ""); if (matches.Any()) { teachers = matches.Select(x => new SelectListItem() { Text = string.Format("{0} ({1})", x.user.ToName(true), x.subject.name), Value = x.user.id.ToString() }); } } else { if (student.schoolid.HasValue) { studentschool = student.schoolid.Value; } } // get principal if (studentschool.HasValue) { var matches = repository.GetUsers(null, null, (int)studentschool, null, UserGroup.HEAD, null, null, null, year, null); if (matches.Any(x => x.email != "" && x.email != null)) { var principal = matches.ToArray().Select(x => new SelectListItem() { Text = x.ToName(true) + " (Principal)", Value = x.id.ToString() }); viewmodel.staffList.AddRange(principal); } } if (teachers != null) { viewmodel.staffList.AddRange(teachers); } if (viewmodel.staffList.Count == 0) { return(SendJsonErrorResponse("Nobody available to contact at the moment")); } return(View(viewmodel)); }