public ActionResult Creation(PilotAndRoleMergeViewModel NewPilot)
        {
            if (NewPilot.PilotDetail.Role.RoleId == -1)
            {
                NewPilot.PilotDetail.Role = null;
            }

            PilotDetailDto pilotDtoToCreate = NewPilot.PilotDetail;

            new DetailedPilot(_context).CreateNewPilot(pilotDtoToCreate);

            return(RedirectToAction("Index"));
        }
Beispiel #2
0
        public void RemovingPilot(PilotDetailDto pilotDetailDto)
        {
            Pilot pilotFromDB = _config.Pilots.Where(p => p.PilotId == pilotDetailDto.Id).IgnoreQueryFilters().First();

            //GET the pilot role (if he had once)
            if (pilotDetailDto.Role != null)
            {
                RemoveRoleFromPilot(pilotFromDB.Role);
            }
            pilotFromDB.IsActive = false;
            pilotFromDB.Role     = null;
            pilotFromDB.RoleId   = null;

            _config.Pilots.Update(pilotFromDB);

            _config.SaveChanges();
        }
Beispiel #3
0
        public PilotDetailDto CreateNewPilot(PilotDetailDto NewDtoPilot)//A CHANGER
        {
            //If the role is defaut (-1) set it to null before send it to the DataBase
            if (NewDtoPilot.Role != null && NewDtoPilot.Role.RoleId == -1)
            {
                NewDtoPilot.Role = null;
            }

            //Creating a real pilot to add it to the database
            Pilot NewPilot = new Pilot()
            {
                FirstName   = NewDtoPilot.FirstName,
                LastName    = NewDtoPilot.LastName,
                Email       = NewDtoPilot.Email,
                PhoneNumber = NewDtoPilot.PhoneNumber,
                IsActive    = true,
                Weight      = NewDtoPilot.Weight,
                Role        = null
            };

            //Adding the new pilot to get an id from the db
            _config.Pilots.Add(NewPilot);

            _config.SaveChanges();

            NewDtoPilot.Id = NewPilot.PilotId;

            if (NewDtoPilot.Role != null)
            {
                Role roleToAddToThePilot = _config.Roles.Where(r => r.RoleId == NewDtoPilot.Role.RoleId).IgnoreQueryFilters().First();
                AddRoleToPilot(roleToAddToThePilot, NewPilot);
            }

            _config.SaveChanges();

            return(NewDtoPilot);
        }
Beispiel #4
0
        public PilotDetailDto UpdatePilot(PilotDetailDto pilotDetailDto)
        {
            //GET the pilot from the database to modify it
            //Pilot pilotFromDB = _config.Pilots.Where(p => p.PilotId == pilotDetailDto.Id).First();
            Pilot pilotFromDB = new Pilot();

            pilotFromDB.PilotId     = pilotDetailDto.Id;
            pilotFromDB.IsActive    = true;
            pilotFromDB.FirstName   = pilotDetailDto.FirstName;
            pilotFromDB.LastName    = pilotDetailDto.LastName;
            pilotFromDB.Email       = pilotDetailDto.Email;
            pilotFromDB.Weight      = pilotDetailDto.Weight;
            pilotFromDB.PhoneNumber = pilotDetailDto.PhoneNumber;
            pilotFromDB.Role        = _config.Roles.Where(r => r.PilotId == pilotFromDB.PilotId).IgnoreQueryFilters().FirstOrDefault();
            if (pilotFromDB.Role != null)
            {
                pilotFromDB.RoleId = pilotFromDB.Role.RoleId;
            }

            //GET the previus pilot role if he had one
            if (pilotFromDB.RoleId != null)
            {
                pilotFromDB.Role = _config.Roles.Where(r => r.RoleId == pilotFromDB.RoleId).IgnoreQueryFilters().First();
            }
            //GET the new pilot role if he is asking for one
            if (pilotDetailDto.Role != null)
            {
                pilotDetailDto.Role = _config.Roles.Where(r => r.RoleId == pilotDetailDto.Role.RoleId).IgnoreQueryFilters().First();
            }

            RoleModificationManager(pilotDetailDto.Role, pilotFromDB);

            _config.SaveChanges();

            return(pilotDetailDto);
        }