コード例 #1
0
        private void AddNewMember()
        {
            Member m =  new Member();

            m.Name = _menuView.GetUserInputLine("Enter new member name");
            m.PersonalNumber = _menuView.GetUserInputLine("Enter new member personal number in the format YYMMDD-NNNN.");

            // Validate input
            if (!Validate(m))
            {
                ShowErrorMessages();
            }
            else
            {
                // Try to save input
                try
                {
                    _memberService.SaveMember(m);
                }
                catch (Exception e)
                {
                    // Print out error
                    _menuView.PrintError(e.Message);
                }
            }
        }
コード例 #2
0
        public void DeleteBoat(Member member, Boat boat)
        {
            // Delete Boat in BoatDAL
            BoatDAL.DeleteBoat(boat);

            // Delete in local MemberList
            member.Boats.Remove(boat);
        }
コード例 #3
0
        public void Delete(Member member)
        {
            // Check if there is a member with this PersonalNumber
            if (MemberDAL.Get(member) != null)
            {
                // Delete member from DB
                MemberDAL.Delete(member);

                // Delete from local MemberList
                MemberList.Remove(FindMemberInLocalList(member));

                //TODO Delete members boats in DB
            }
            else
            {
                throw new Exception(String.Format("No member with personal number '{0}' or id '{1}' could be found: {0}", member.PersonalNumber, member.Id));
            }
        }
コード例 #4
0
        public void DeleteMember(Member member)
        {
            // Check if there is a member with this PersonalNumber
            if (MemberDAL.Get(member) != null)
            {
                // Delete boats in DAL
                foreach (Boat boat in member.Boats)
                {
                    BoatDAL.DeleteBoat(boat);
                }

                // Delete member in DAL
                MemberDAL.Delete(member);

                // Delete from local MemberList
                MemberList.Remove(GetMember(member));
            }
            else
            {
                throw new Exception(String.Format("No member with personal number '{0}' or id '{1}' could be found: {0}", member.PersonalNumber, member.Id));
            }
        }
コード例 #5
0
        private void AddBoat(Member member, Boat boat)
        {
            // Add boat in BoatDAL
            BoatDAL.RegisterNewBoat(boat, member);

            // Add member id to boat, in case this is not done.
            boat.MemberId = member.Id;

            // Add boat in local MemberList
            member.Boats.Add(boat);
        }
コード例 #6
0
 public void SaveBoat(Member member, Boat boat)
 {
     // If boat does not exist in member
     if (GetBoat(member, boat) == null)
     {
         AddBoat(member, boat);
     }
     else
     {
         UpdateBoat(member, boat);
     }
 }
コード例 #7
0
 // Public Methods
 // Member
 public void SaveMember(Member member)
 {
     // If a new member should be added
     if (member.Id == 0)
     {
         AddMember(member);
     }
     else
     {
         UpdateMember(member);
     }
 }
コード例 #8
0
 public Member GetMember(Member member)
 {
     // Match by id number or personal number
     return MemberList.Find(x => (x.Id == member.Id) || (x.PersonalNumber == member.PersonalNumber));
 }
コード例 #9
0
 public List<Member> GetMembers(Member member)
 {
     return MemberList.FindAll(x => (x.Id == member.Id) || (x.PersonalNumber == member.PersonalNumber));
 }
コード例 #10
0
        private void UpdateBoat(Member member, Boat boat)
        {
            // Update boat in BoatDAL
            BoatDAL.EditBoat(boat);

            // Update boat in local MembersList
            int _index = member.Boats.IndexOf(GetBoat(member, boat));
            member.Boats[_index] = boat;
        }
コード例 #11
0
 // Private Methods
 private Member FindMemberInLocalList(Member member)
 {
     // Match by id number or personal number
     return MemberList.Find(x => (x.Id == member.Id) || (x.PersonalNumber == member.PersonalNumber));
 }
コード例 #12
0
ファイル: MemberDAL.cs プロジェクト: jt222ii/1dv607workshop2
 public void addMemberToList(Member member)
 {
     memberList.Add(member);
 }
コード例 #13
0
ファイル: Console.cs プロジェクト: jt222ii/1dv607workshop2
 public void showMember(Member member)
 {
     System.Console.Clear();
     System.Console.WriteLine("Name: {0} {1} SSN: {2} ID: {3}", member.FirstName, member.LastName, member.SSN, member.MemberID);
     showMemberBoats(member);
     System.Console.WriteLine("════════════════════════════════════════════════════\n");
     System.Console.WriteLine("What do you want to do?\n 1 - to delete\n 2 - to change First Name\n 3 - to change Last Name\n 4 - to change Social security number\n 5 - Add a boat\n 6 - Inspect boat\n 0 - Main Menu");
 }
コード例 #14
0
 public Member Get(Member member)
 {
     return FindMemberInLocalList(member);
 }
コード例 #15
0
 // Public Methods
 public void Save(Member member)
 {
     // If a new member should be added
     if (member.Id == 0)
     {
         Add(member);
     }
     // Member should be updated
     else
     {
         Update(member);
     }
 }
コード例 #16
0
ファイル: Console.cs プロジェクト: jt222ii/1dv607workshop2
 public void showMemberBoats(Member member)
 {
     int boatNumber = 1;
     foreach (Boat boat in member.BoatList)
     {
         System.Console.WriteLine(string.Format("\t{0}: TYPE: {1}, LENGTH: {2}m", boatNumber, boat.BoatType.ToString(), boat.Length));
         boatNumber++;
     }
 }
コード例 #17
0
        private void Update(Member member)
        {
            Member _memberFromList;

            // Get member from list searching by properties: Id, PersonalNumber
            _memberFromList = Get(member);

            // Check if there is no member to update
            if (_memberFromList == null)
            {
                throw new Exception(String.Format("No member with personal number '{0}' or id '{1}' could be found: {0}", member.PersonalNumber, member.Id));
            }
            // Check if the desired personal number is already taken. MemberDAL.Get() matches members by PersonalNumber and Id.
            else if (_memberFromList.Id != member.Id)
            {
                throw new Exception(String.Format("There is already a member with this personal number: {0}", member.PersonalNumber));
            }

            // Update member in database
            MemberDAL.Update(member);

            // Update local MemberList
            MemberList[MemberList.IndexOf(FindMemberInLocalList(member))] = member;
        }
コード例 #18
0
 private List<Boat> GetBoatsForMember(Member member)
 {
     return new List<Boat>();
 }
コード例 #19
0
        private void AddMember(Member member)
        {
            // Check if there is a member with this PersonalNumber already
            if(GetMember(member) != null)
            {
                throw new Exception(String.Format("There is already a member with this personal number: {0}", member.PersonalNumber));
            }

            // Add member to database
            int insertId = MemberDAL.Add(member);

            // Update id on member
            member.Id = insertId;

            // Add member to local Memberlist
            MemberList.Add(member);
        }
コード例 #20
0
ファイル: User.cs プロジェクト: jt222ii/1dv607workshop2
        public void StartApplication()
        {
            mDAL = new MemberDAL();
                c = new View.Console();
                try
                {
                    mDAL.LoadMembersFromBin();
                }
                catch (Exception e)
                {

                    c.ErrorMessage(e);
                }
                while (true)
                {
                    try
                    {
                        c.DisplayInstructions();
                        int userInput = int.Parse(c.GetUserInput());
                        IReadOnlyCollection<Member> list = mDAL.getMemberList();
                        switch (userInput)
                        {
                            case 1: // save and quit
                                mDAL.SaveMembersToBin();
                                Environment.Exit(0);
                                break;
                            case 2: // add member
                                Console.Clear();
                                while (true)
                                {
                                    c.addMemberInstructionPrompt();
                                    try
                                    {
                                        //fname, lname, ssn
                                        m = new Member(c.GetUserInput(), c.GetUserInput(), c.GetUserInput());
                                        mDAL.addMemberToList(m);
                                    }
                                    catch
                                    {
                                        throw new ArgumentException();
                                    }
                                    break;
                                }

                                break;
                            case 3: // show compact list
                                Console.Clear();
                                c.showMembersCompact(list);
                                selectMember(list);
                                break;
                            case 4: // show verbose list
                                Console.Clear();
                                c.showMembersVerbose(list);
                                selectMember(list);
                                break;
                            default:
                                break;
                        }
                    }
                    catch (Exception e)
                    {
                        c.ErrorMessage(e);
                    }
                }
        }
コード例 #21
0
 private List<Boat> GetBoatsForMember(Member member)
 {
     return BoatDAL.GetBoats(new Boat { MemberId = member.Id });
 }
コード例 #22
0
        public Boat GetBoat(Member member, Boat boat)
        {
            // Return null if the boat has no valid id. It's a new boat perhaps?
            if (boat.BoatId == 0)
            {
                return null;
            }

            return member.Boats.Find(x => (x.BoatId == boat.BoatId));
        }
コード例 #23
0
        private void UpdateMember(Member member)
        {
            List<Member> _otherMembersWithSamePnumber;

            // Get other members with same Personal number
            _otherMembersWithSamePnumber = GetMembers(new Member{PersonalNumber = member.PersonalNumber});

            // Check if the desired personal number is already taken.
            if (_otherMembersWithSamePnumber.Count > 1)
            {
                throw new Exception(String.Format("There is already a member with this personal number: {0}", member.PersonalNumber));
            }

            // Update member in database
            MemberDAL.Update(member);

            // Update local MemberList
            MemberList[MemberList.IndexOf(GetMember(member))] = member;
        }
コード例 #24
0
        // Test all methods
        public void TestAll()
        {
            // Create a test member
            Member member = new Member
            {
                Name = "Test Member",
                PersonalNumber = "321010-1234"
            };

            // Add test member to database
            Add(member);

            // Get test member from database
            Get(member);

            // Delete member from database
            Delete(member);

            // Get all members from database
            GetAll();
        }
コード例 #25
0
 public Boat GetBoat(Member member, int boatId)
 {
     return GetBoat(member, new Boat { BoatId = boatId });
 }
コード例 #26
0
ファイル: User.cs プロジェクト: jt222ii/1dv607workshop2
        public void updateBoat(Member member)
        {
            int choice = int.Parse(c.GetUserInput());
            if (choice == 0)
            {
                return;
            }
            choice--;
            Boat chosenBoat = member.BoatList.ElementAt(choice);
            c.showBoat(chosenBoat);
            int boatOption = int.Parse(c.GetUserInput());
            switch(boatOption){
                case 1: // change boat
                    c.showBoatTypes();
                    int newType = int.Parse(c.GetUserInput())-1;
                    c.boatLengthPrompt();
                    double newLength = double.Parse(c.GetUserInput());
                    member.ChangeBoat(chosenBoat, newType, newLength);
                    break;
                case 2: // remove boat
                    member.RemoveBoat(choice);
                    break;
                default:
                    break;

            }
        }