public ActionResult Create(TrainerProfile trainerProfile) { if (!ModelState.IsValid) { return(View("~/Views/CheckTrainerProfileConditions/CreateNullTrainerProfile.cshtml")); } //Check if Trainer Profile existed or not if (_context.TrainerProfiles.Any(c => c.TrainerId == trainerProfile.TrainerId)) { return(View("~/Views/CheckTrainerProfileConditions/CreateExistTrainerProfile.cshtml")); } var getTrainerProfile = new TrainerProfile { TrainerId = trainerProfile.TrainerId, Full_Name = trainerProfile.Full_Name, External_Internal = trainerProfile.External_Internal, Education = trainerProfile.Education, Working_Place = trainerProfile.Working_Place, Phone_Number = trainerProfile.Phone_Number }; _context.TrainerProfiles.Add(getTrainerProfile); _context.SaveChanges(); return(View("~/Views/CheckTrainerProfileConditions/CreateTrainerProfileSuccess.cshtml")); }
public ActionResult Edit(TrainerProfile trainerProfile) { if (!ModelState.IsValid) { return(View()); } var trainerProfileInDb = _context.TrainerProfiles.SingleOrDefault(trdb => trdb.Id == trainerProfile.Id); if (trainerProfileInDb == null) { return(HttpNotFound()); } trainerProfileInDb.TrainerId = trainerProfile.TrainerId; trainerProfileInDb.Full_Name = trainerProfile.Full_Name; trainerProfileInDb.External_Internal = trainerProfile.External_Internal; trainerProfileInDb.Education = trainerProfile.Education; trainerProfileInDb.Working_Place = trainerProfile.Working_Place; trainerProfileInDb.Phone_Number = trainerProfile.Phone_Number; _context.SaveChanges(); if (User.IsInRole("TrainingStaff")) { return(RedirectToAction("Index")); } if (User.IsInRole("Trainer")) { return(RedirectToAction("Mine")); } return(RedirectToAction("Index")); }
public ActionResult Create() { //Get Account Trainer var roleInDb = (from r in _context.Roles where r.Name.Contains("Trainer") select r) .FirstOrDefault(); var users = _context.Users.Where(x => x.Roles.Select(y => y.RoleId) .Contains(roleInDb.Id)) .ToList(); var trainerProfiles = _context.TrainerProfiles.ToList(); var trainerProfile = new TrainerProfile { Trainers = users, }; return(View(trainerProfile)); }