Exemplo n.º 1
0
        public async Task PilotDetails_ToDLModelShouldMapToPilotDetails()
        {
            var newPilot = new Pilot
            {
                ID        = 1,
                PilotName = "name",
                Producer  = new User {
                    ID = 1, UserName = "******"
                },
                PilotDescription = "description",
                Scenes           = new List <Scene> {
                    new Scene {
                        SceneFiles = new List <SceneFile> {
                            new SceneFile()
                        }
                    }
                },
                Files = new List <File> {
                    new File {
                        Uploader = new User()
                    }
                },
                Script = new Script {
                    ScriptWriter = new User()
                }
            };
            var result = PilotDetails.FromDLModel(newPilot);

            Assert.Equal(newPilot.ID, result.ID);
            Assert.Equal(newPilot.PilotName, result.PilotName);
            Assert.Equal(newPilot.PilotDescription, result.PilotDescription);
            Assert.Equal(newPilot.Producer.ID, result.Producer.ID);
            Assert.Equal(newPilot.Producer.UserName, result.Producer.UserName);
        }
Exemplo n.º 2
0
        public ActionResult PilotEdit(PilotDetails pilot)
        {
            var db    = new PilotDbContext();
            var entry = db.Entry(pilot);

            if (ModelState.IsValid)
            {
                entry.State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Pilots", "Admin"));
            }
            return(View(entry));
        }
        public ActionResult PilotRegister(PilotDetails admin)
        {
            var pilot = new PilotDetails
            {
                PilotID         = admin.PilotID,
                Password        = admin.Password,
                ConfirmPassword = admin.ConfirmPassword,
                FirstName       = admin.FirstName,
                LastName        = admin.LastName,
                Age             = admin.Age,
                Gender          = admin.Gender,
                ContactNumber   = admin.ContactNumber,
                RoleID          = admin.RoleID,
                isApproved      = admin.isApproved
            };

            if (ModelState.IsValid)
            {
                var context  = new PilotDbContext();
                var isUnique = context.Pilots.Where(n => n.PilotID == admin.PilotID);
                foreach (var i in isUnique)
                {
                    if (i.PilotID == admin.PilotID)
                    {
                        ViewData["Error"] = "PilotID Already Exists";
                        return(View(admin));
                    }
                }

                admin.RoleID = 3;
                context.Pilots.Add(admin);
                context.SaveChanges();

                var pilot_schedule = new PilotSchedule()
                {
                    PilotID = admin.PilotID,
                    PilotAvailabilityFrom = null,
                    PilotAvailabilityTo   = null,
                    IsActive = false
                };

                var pils = new AdminDbContext();
                pils.PilotS.Add(pilot_schedule);
                pils.SaveChanges();

                TempData["saved"] = "Pilot Details Added Successfully!";
                return(RedirectToAction("PilotLogin"));
            }
            return(View());
        }
 public PilotDetails GetById(int id)
 {
     return(PilotDetails.FromDLModel(_aviBL.GetPilotByID(id)));
 }