Exemplo n.º 1
0
        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"));
        }
Exemplo n.º 2
0
        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"));
        }
Exemplo n.º 3
0
        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));
        }