Beispiel #1
0
        public AircraftEditViewModel(Aircraft entity)
        {
            Id = entity.Id;
            Name = entity.Name;
            RegistrationNumber = entity.RegistrationNumber;
            this.Model = entity.Model;
            TypeDesignation = entity.TypeDesignation;
            Make = entity.Make;
            Year = entity.Year;
            MaxGrossWeight = entity.MaxGrossWeight;
            FuelCapacity = entity.FuelCapacity;
            //FuelTabCapacity = entity.FuelTabCapacity;
            UsefulLoad = entity.UsefulLoad;
            //EmptyWeight = entity.EmptyWeight;
            //EmptyCG = entity.EmptyCG;
            CruiseSpeed = entity.CruiseSpeed;
            MaxRange = entity.MaxRange;
            Description = entity.Description;
            EquipmentList = entity.EquipmentList;
            CheckoutRequirements = entity.CheckoutRequirements;
            OperationalNotes = entity.OperationalNotes;
            HourlyRate = entity.HourlyRate;
            BasedAt = entity.BasedAt;
            Status = entity.Status;
            StatusNotes = entity.StatusNotes;

            if (entity.Owners != null)
                Owners = entity.Owners.Select(o =>
                    new AircraftOwnerInfo() { OwnerId = o.Id, Name = o.FirstName + " " + o.LastName })
                    .ToList();
            if (entity.Images != null)
                Images = entity.Images.ToList();

            StatusValues = new SelectList(Enum.GetValues(typeof(AircraftStatus)).Cast<AircraftStatus>().Select(i => i.ToString()).ToList(), entity.Status);

        }
 public void UpdateAircraft(Aircraft aircraft)
 {
     _repository.Attach<Aircraft>(aircraft);
     _repository.UnitOfWork.SaveChanges();
 }
 public Aircraft AddAircraft(Aircraft aircraft)
 {
     _repository.Add<Aircraft>(aircraft);
     _repository.UnitOfWork.SaveChanges();
     return _repository.FindOne<Aircraft>(a => a.RegistrationNumber == aircraft.RegistrationNumber);
 }
 private Aircraft CopyDataFromViewModel(Aircraft entity, AircraftEditViewModel viewModel)
 {
     entity.Year = viewModel.Year;
     entity.BasedAt = viewModel.BasedAt;
     entity.Make = viewModel.Make;
     entity.CheckoutRequirements = viewModel.CheckoutRequirements;
     entity.CruiseSpeed = viewModel.CruiseSpeed;
     entity.Description = viewModel.Description;
     entity.EquipmentList = viewModel.EquipmentList;
     entity.FuelCapacity = viewModel.FuelCapacity;
     entity.HourlyRate = viewModel.HourlyRate;
     entity.MaxGrossWeight = viewModel.MaxGrossWeight;
     entity.MaxRange = viewModel.MaxRange;
     entity.Model = viewModel.Model;
     entity.Name = viewModel.Name;
     entity.OperationalNotes = viewModel.OperationalNotes;
     entity.RegistrationNumber = viewModel.RegistrationNumber;
     entity.Status = viewModel.Status;
     entity.StatusNotes = viewModel.StatusNotes;
     entity.TypeDesignation = viewModel.TypeDesignation;
     entity.UsefulLoad = viewModel.UsefulLoad;
     return entity;
 }
        public ActionResult Create(AircraftEditViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                if (_dataService.GetAircraftByRegNumber(viewModel.RegistrationNumber) == null)
                {
                    Aircraft entity = new Aircraft();
                    entity = CopyDataFromViewModel(entity, viewModel);
                    _dataService.AddAircraft(entity);
                    return RedirectToAction("Index");
                }
                else
                {
                    ModelState.AddModelError("RegistrationNumber", "Aircraft with registration number already exists in the database");
                }
            }

            return View(viewModel);
        }
        //public void ImportMembers()
        //{
        //    IEnumerator<NtfcDataSet.MembershipRow> rows = _dataSet.Membership.GetEnumerator();
        //    while (rows.MoveNext())
        //    {
        //        var srcMember = rows.Current;
        //        Login login = _dbContext.Logins.FirstOrDefault(l => l.Username == srcMember.Member_ID);
        //        // skip users that don't have logins
        //        if (login == null)
        //            continue;

        //        if (srcMember.IsFirst_NameNull())
        //            continue;

        //        if (srcMember.First_Name.Trim() == String.Empty || srcMember.First_Name == "----")
        //            continue;

        //        Member member = new Member();
        //        member.LoginId = login.Id;
        //        member.AddressLine_1 = !srcMember.IsAddressNull() ? srcMember.Address : null;
        //        member.Phone = !srcMember.IsHome_PhoneNull() ? srcMember.Home_Phone : null;
        //        member.AltPhone = !srcMember.IsWork_PhoneNull() ? srcMember.Work_Phone : null;
        //        member.City = !srcMember.IsCityNull() ? srcMember.City : null;
        //        member.Zip = !srcMember.IsZipNull() ? srcMember.Zip : null;
        //        member.PrimaryEmail = !srcMember.IsEmailNull() ? srcMember.Email : null;
        //        member.SecondaryEmail = !srcMember.Isemail2Null() ? srcMember.email2 : null;
        //        member.EmergencyName = !srcMember.IsE_First_NameNull() ? srcMember.E_First_Name + srcMember.E_Last_Name : null;
        //        member.EmergencyPhone = !srcMember.IsE_Home_PhoneNull() ? srcMember.E_Home_Phone : null;
        //        member.FirstName = srcMember.First_Name;
        //        member.LastName = srcMember.Last_Name;
        //        member.LastMedical = !srcMember.IsMedical_DateNull() ? (DateTime?)srcMember.Medical_Date : null; 
        //        member.MemberSince = srcMember.Membership_Date;
        //        if (!srcMember.IsBirthdateNull())
        //        {
        //            DateTime dob = DateTime.MinValue;
        //            if (DateTime.TryParse(srcMember.Birthdate, out dob))
        //                member.BirthDate = dob;
        //        }
        //        member.PilotStatus = !srcMember.IsPilot_statusNull() ? srcMember.Pilot_status : null;

        //        _dbContext.Members.Add(member);
        //    }
        //    _dbContext.SaveChanges();
        //}

        public void ImportAircraft()
        {
            IEnumerator<NtfcDataSet.AircraftRow> rows = _dataSet.Aircraft.GetEnumerator();
            Role ownerRole = _dbContext.Roles.First(r => r.Name.Contains("Owner"));
            while (rows.MoveNext())
            {
                var row = rows.Current;
                if (row.Tail_No == "N971BG" || row.Tail_No == "N2590H")
                    continue;

                Aircraft aircraft = new Aircraft();
                aircraft.Year = "";
                aircraft.Make = "";
                aircraft.CheckoutRequirements = row.Checkout;
                aircraft.CruiseSpeed = Convert.ToInt16(row.Speed);
                aircraft.Description = row.Description;
                aircraft.EquipmentList = row.Equipment;
                aircraft.FuelCapacity = Convert.ToInt16(row.FuelCap);
                aircraft.HourlyRate = Convert.ToInt16(row.Hourly_Rate);
                aircraft.MaxGrossWeight = Convert.ToInt16(row.MaxGrossWgt);
                aircraft.MaxRange = Convert.ToInt16(row.Range);
                aircraft.Model = row.Model;
                aircraft.Name = String.Empty;
                aircraft.RegistrationNumber = row.Tail_No;
                aircraft.Status = AircraftStatus.Online.ToString();
                aircraft.StatusNotes = String.Empty;
                aircraft.TypeDesignation = String.Empty;
                aircraft.UsefulLoad = (int)Convert.ToDouble(row.UsefulLoad);
                aircraft.TypeDesignation = row.AC_Type;
                aircraft.BasedAt = "TKI";
        
                Login owner1 = _dbContext.Logins.Where(l => l.MemberPIN == row.Owner_MID).Include(l => l.ClubMember).FirstOrDefault();
                owner1.ClubMember.First().Roles.Add(ownerRole);
                aircraft.Owners = new List<Member>();
                aircraft.Owners.Add(owner1.ClubMember.First());

                if (!row.Isowner2_MIDNull())
                {
                    string id = row.owner2_MID;
                    Login owner2 = _dbContext.Logins.Where(l => l.MemberPIN == id).Include(l => l.ClubMember).FirstOrDefault();
                    if (owner2 != null)
                    {
                        owner2.ClubMember.First().Roles.Add(ownerRole);
                        aircraft.Owners.Add(owner2.ClubMember.First());
                    }     
                }

                _dbContext.Aircraft.Add(aircraft);
                _dbContext.SaveChanges();               
            }
        }