Exemplo n.º 1
0
        public override void DoOperation()
        {
            try
            {
                //Validate Reques Header / Constants
                this.baseResponseMessage = ValidateInput();
                if (!this.baseResponseMessage.header.IsSuccess)
                {
                    throw new Exception(this.baseResponseMessage.header.ResponseMessage);
                }

                //Operation
                switch (this.request.Header.OperationTypes)
                {
                case (int)OperationType.OperationTypes.ADD:
                    #region ADD
                    long checkGuid = 0;
                    this.favorite = new Favorites
                    {
                        INSERT_USER     = this.request.INSERT_USER,
                        UPDATE_USER     = this.request.UPDATE_USER,
                        CUSTOMER_NUMBER = this.request.CUSTOMER_NUMBER,
                        BOAT_ID         = this.request.BOAT_ID
                    };

                    checkGuid     = Favorites.Insert(this.favorite);
                    this.response = new ResponseFavorites
                    {
                        BOAT_ID         = this.request.BOAT_ID,
                        CUSTOMER_NUMBER = this.favorite.CUSTOMER_NUMBER,
                        header          = new ResponseHeader
                        {
                            IsSuccess       = checkGuid == 0 ? false : true,
                            ResponseCode    = checkGuid == 0 ? CommonDefinitions.INTERNAL_SYSTEM_UNKNOWN_ERROR : CommonDefinitions.SUCCESS,
                            ResponseMessage = checkGuid == 0 ? CommonDefinitions.ERROR_MESSAGE : CommonDefinitions.SUCCESS_MESSAGE
                        }
                    };
                    #endregion
                    break;

                case (int)OperationType.OperationTypes.GET:
                    #region GET
                    listfavorites = Favorites.SelectByCustomerNumber(this.request.CUSTOMER_NUMBER);
                    //Take all favorites for CustomerNumber
                    foreach (var item in listfavorites)
                    {
                        this.response = new ResponseFavorites
                        {
                            CUSTOMER_NUMBER = item.CUSTOMER_NUMBER,
                            BOAT_ID         = item.BOAT_ID,
                            header          = new ResponseHeader
                            {
                                IsSuccess       = true,
                                ResponseCode    = CommonDefinitions.SUCCESS,
                                ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                            }
                        };
                        responseAllFavorite.Add(this.response);
                    }

                    //Take All Boat Info for Favorites
                    this.listboat   = Boats.SelectAllBoat();
                    this.listregion = Region.SelectAllRegion();
                    foreach (var item in responseAllFavorite)
                    {
                        this.boat          = this.listboat.Where(s => s.BOAT_ID == item.BOAT_ID).FirstOrDefault();
                        this.responseBoats = new ResponseBoats
                        {
                            BOAT_ID     = this.boat.BOAT_ID,
                            BOAT_INFO   = this.boat.BOAT_INFO,
                            BOAT_NAME   = this.boat.BOAT_NAME,
                            CAPTAIN_ID  = this.boat.CAPTAIN_ID,
                            FLAG        = this.boat.FLAG,
                            QUANTITY    = this.boat.QUANTITY,
                            REGION_ID   = this.boat.REGION_ID,
                            ROTA_INFO   = this.boat.ROTA_INFO,
                            REGION_NAME = Enum.GetName(typeof(Enums.Region), this.boat.REGION_ID),
                            header      = new ResponseHeader
                            {
                                IsSuccess       = true,
                                ResponseCode    = CommonDefinitions.SUCCESS,
                                ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                            }
                        };

                        reponseAllBoats.Add(this.responseBoats);
                    }

                    #endregion
                    break;

                case (int)OperationType.OperationTypes.DELETE:
                    #region DELETE
                    if (!this.request.IsDeleteByCustomerNumber)
                    {
                        this.favorite = new Favorites
                        {
                            INSERT_USER     = this.request.INSERT_USER,
                            UPDATE_USER     = this.request.UPDATE_USER,
                            CUSTOMER_NUMBER = this.request.CUSTOMER_NUMBER,
                            BOAT_ID         = this.request.BOAT_ID
                        };

                        if (Favorites.Delete(this.favorite))
                        {
                            this.response = new ResponseFavorites
                            {
                                CUSTOMER_NUMBER = this.favorite.CUSTOMER_NUMBER,
                                BOAT_ID         = this.favorite.BOAT_ID,
                                header          = new ResponseHeader
                                {
                                    IsSuccess       = true,
                                    ResponseCode    = CommonDefinitions.SUCCESS,
                                    ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                                }
                            };
                        }
                    }
                    else
                    {
                        //Delete all Favorites Boats for customer
                        if (Favorites.DeleteAllforCustomer(this.favorite.CUSTOMER_NUMBER))
                        {
                            this.response = new ResponseFavorites
                            {
                                CUSTOMER_NUMBER = this.favorite.CUSTOMER_NUMBER,
                                BOAT_ID         = this.favorite.BOAT_ID,
                                header          = new ResponseHeader
                                {
                                    IsSuccess       = true,
                                    ResponseCode    = CommonDefinitions.SUCCESS,
                                    ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                                }
                            };
                        }
                    }

                    #endregion
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                string operationError = "HATA:[" + "CustomerNumber:" + this.request.CUSTOMER_NUMBER + ",ResponseCode:" + this.baseResponseMessage.header.ResponseCode + ", ResponseMessage:" + ex.Message + "]";
                log.InfoFormat(operationError, ex);
                throw new Exception(ex.Message, ex.InnerException);
            }
        }
Exemplo n.º 2
0
        public void ReadDockData()
        {
            string data = File.ReadAllText(DataPath);

            if (data == "")
            {
                //empty harbour
            }
            else
            {
                string[] dockSplit  = data.Split('_');
                string[] dockOne    = dockSplit[0].Split('\n', StringSplitOptions.RemoveEmptyEntries);
                string[] removeShit = dockSplit[1].Split('\n', StringSplitOptions.RemoveEmptyEntries);
                string[] dockTwo    = removeShit.Skip(1)
                                      .ToArray();

                foreach (var item in dockOne)
                {
                    if (item == dockOne[0])
                    {
                        string[] counters = item.Split('-');
                        Day           = int.Parse(counters[0]);
                        RejectedBoats = int.Parse(counters[1]);
                        AddedBoats    = int.Parse(counters[2]);
                    }
                    else
                    {
                        string[] boats = item.Split(',');

                        if (boats[0].ToLower() == "sailboat" && !Array.Exists(DockOne, b => b != null && b.ID == boats[1]))
                        {
                            SailBoat sail = new SailBoat()
                            {
                                ID           = boats[1],
                                Weight       = int.Parse(boats[2]),
                                MaxSpeed     = int.Parse(boats[3]),
                                LengthInFeet = int.Parse(boats[4]),
                                DaysDocked   = int.Parse(boats[5])
                            };
                            sail.Docked = true;
                            Array.Fill(DockOne, sail, Counter, sail.Slots);
                            Boats.Add(sail);
                        }
                        if (boats[0].ToLower() == "rowingboat" && !Array.Exists(DockOne, b => b != null && b.ID == boats[1]))
                        {
                            RowingBoat row = new RowingBoat()
                            {
                                ID           = boats[1],
                                Weight       = int.Parse(boats[2]),
                                MaxSpeed     = int.Parse(boats[3]),
                                MaxPassenger = int.Parse(boats[4]),
                                DaysDocked   = int.Parse(boats[5])
                            };
                            row.Docked = true;

                            Array.Fill(DockOne, row, Counter, row.Slots);
                            Boats.Add(row);
                        }
                        if (boats[0].ToLower() == "powerboat" && !Array.Exists(DockOne, b => b != null && b.ID == boats[1]))
                        {
                            PowerBoat power = new PowerBoat()
                            {
                                ID                 = boats[1],
                                Weight             = int.Parse(boats[2]),
                                MaxSpeed           = int.Parse(boats[3]),
                                NumberOfHorsepower = int.Parse(boats[4]),
                                DaysDocked         = int.Parse(boats[5])
                            };
                            power.Docked = true;

                            Array.Fill(DockOne, power, Counter, power.Slots);
                            Boats.Add(power);
                        }
                        if (boats[0].ToLower() == "catamaran" && !Array.Exists(DockOne, b => b != null && b.ID == boats[1]))
                        {
                            Catamaran catamaran = new Catamaran()
                            {
                                ID         = boats[1],
                                Weight     = int.Parse(boats[2]),
                                MaxSpeed   = int.Parse(boats[3]),
                                Beds       = int.Parse(boats[4]),
                                DaysDocked = int.Parse(boats[5])
                            };
                            catamaran.Docked = true;

                            Array.Fill(DockOne, catamaran, Counter, catamaran.Slots);
                            Boats.Add(catamaran);
                        }
                        if (boats[0].ToLower() == "cargoship" && !Array.Exists(DockOne, b => b != null && b.ID == boats[1]))
                        {
                            CargoShip cargo = new CargoShip()
                            {
                                ID              = boats[1],
                                Weight          = int.Parse(boats[2]),
                                MaxSpeed        = int.Parse(boats[3]),
                                CargoContainers = int.Parse(boats[4]),
                                DaysDocked      = int.Parse(boats[5])
                            };
                            cargo.Docked = true;

                            Array.Fill(DockOne, cargo, Counter, cargo.Slots);
                            Boats.Add(cargo);
                        }

                        Counter++;
                    }
                }
                Counter = 0;
                foreach (var item in dockTwo)
                {
                    string[] boats = item.Split(',');

                    if (boats[0].ToLower() == "sailboat" && !Array.Exists(DockTwo, b => b != null && b.ID == boats[1]))
                    {
                        SailBoat sail = new SailBoat()
                        {
                            ID           = boats[1],
                            Weight       = int.Parse(boats[2]),
                            MaxSpeed     = int.Parse(boats[3]),
                            LengthInFeet = int.Parse(boats[4]),
                            DaysDocked   = int.Parse(boats[5])
                        };
                        sail.Docked = true;
                        Array.Fill(DockTwo, sail, Counter, sail.Slots);
                        Boats.Add(sail);
                    }
                    if (boats[0].ToLower() == "rowingboat" && !Array.Exists(DockTwo, b => b != null && b.ID == boats[1]))
                    {
                        RowingBoat row = new RowingBoat()
                        {
                            ID           = boats[1],
                            Weight       = int.Parse(boats[2]),
                            MaxSpeed     = int.Parse(boats[3]),
                            MaxPassenger = int.Parse(boats[4]),
                            DaysDocked   = int.Parse(boats[5])
                        };
                        row.Docked = true;

                        Array.Fill(DockTwo, row, Counter, row.Slots);
                        Boats.Add(row);
                    }
                    if (boats[0].ToLower() == "powerboat" && !Array.Exists(DockTwo, b => b != null && b.ID == boats[1]))
                    {
                        PowerBoat power = new PowerBoat()
                        {
                            ID                 = boats[1],
                            Weight             = int.Parse(boats[2]),
                            MaxSpeed           = int.Parse(boats[3]),
                            NumberOfHorsepower = int.Parse(boats[4]),
                            DaysDocked         = int.Parse(boats[5])
                        };
                        power.Docked = true;

                        Array.Fill(DockTwo, power, Counter, power.Slots);
                        Boats.Add(power);
                    }
                    if (boats[0].ToLower() == "catamaran" && !Array.Exists(DockTwo, b => b != null && b.ID == boats[1]))
                    {
                        Catamaran catamaran = new Catamaran()
                        {
                            ID         = boats[1],
                            Weight     = int.Parse(boats[2]),
                            MaxSpeed   = int.Parse(boats[3]),
                            Beds       = int.Parse(boats[4]),
                            DaysDocked = int.Parse(boats[5])
                        };
                        catamaran.Docked = true;

                        Array.Fill(DockTwo, catamaran, Counter, catamaran.Slots);
                        Boats.Add(catamaran);
                    }
                    if (boats[0].ToLower() == "cargoship" && !Array.Exists(DockTwo, b => b != null && b.ID == boats[1]))
                    {
                        CargoShip cargo = new CargoShip()
                        {
                            ID              = boats[1],
                            Weight          = int.Parse(boats[2]),
                            MaxSpeed        = int.Parse(boats[3]),
                            CargoContainers = int.Parse(boats[4]),
                            DaysDocked      = int.Parse(boats[5])
                        };
                        cargo.Docked = true;

                        Array.Fill(DockTwo, cargo, Counter, cargo.Slots);
                        Boats.Add(cargo);
                    }

                    Counter++;
                }
            }
            Counter = 0;
        }
Exemplo n.º 3
0
        public void GenerateBoat(int amount)
        {
            for (int boat = 0; boat < amount; boat++)
            {
                int avaliableSpace = 0;

                switch (Rand.Next(1, 5 + 1))
                {
                case 1:
                    SailBoat s = new SailBoat();


                    for (int i = 0; i < DockTwo.Length; i += 2)
                    {
                        if (DockTwo[i] == null)
                        {
                            avaliableSpace += 2;

                            if (avaliableSpace == s.Slots)
                            {
                                Array.Fill(DockTwo, s, i + 2 - s.Slots, s.Slots);
                                Boats.Add(s);
                                s.Docked = true;

                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    avaliableSpace = 0;
                    if (s.Docked == false)
                    {
                        for (int i = 0; i < DockOne.Length; i += 2)
                        {
                            if (DockOne[i] == null)
                            {
                                avaliableSpace += 2;
                                if (avaliableSpace == s.Slots)
                                {
                                    Array.Fill(DockOne, s, i + 2 - s.Slots, s.Slots);
                                    Boats.Add(s);
                                    s.Docked = true;

                                    break;
                                }
                            }
                            else
                            {
                                avaliableSpace = 0;
                            }
                        }
                    }
                    _ = Boats.Contains(s) ? AddedBoats++ : RejectedBoats++;


                    break;

                case 2:
                    RowingBoat r = new RowingBoat();


                    for (int i = 0; i < DockOne.Length; i++)
                    {
                        if (DockOne[i] == null)
                        {
                            Array.Fill(DockOne, r, i, r.Slots);
                            Boats.Add(r);
                            r.Docked = true;
                            break;
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    avaliableSpace = 0;
                    if (r.Docked == false)
                    {
                        for (int i = 0; i < DockTwo.Length; i++)
                        {
                            if (DockTwo[i] == null)
                            {
                                Array.Fill(DockTwo, r, i, r.Slots);
                                Boats.Add(r);
                                r.Docked = true;
                                break;
                            }
                            else
                            {
                                avaliableSpace = 0;
                            }
                        }
                    }
                    _ = Boats.Contains(r) ? AddedBoats++ : RejectedBoats++;


                    break;

                case 3:
                    PowerBoat p = new PowerBoat();


                    for (int i = 0; i < DockOne.Length; i += 2)
                    {
                        if (DockOne[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace > p.Slots)
                            {
                                Array.Fill(DockOne, p, i - p.Slots, p.Slots);
                                Boats.Add(p);
                                p.Docked = true;
                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    avaliableSpace = 0;
                    if (p.Docked == false)
                    {
                        for (int i = 0; i < DockTwo.Length; i += 2)
                        {
                            if (DockTwo[i] == null)
                            {
                                avaliableSpace += 2;
                                if (avaliableSpace > p.Slots)
                                {
                                    Array.Fill(DockTwo, p, i - p.Slots, p.Slots);
                                    Boats.Add(p);
                                    p.Docked = true;
                                    break;
                                }
                            }
                            else
                            {
                                avaliableSpace = 0;
                            }
                        }
                    }
                    _ = Boats.Contains(p) ? AddedBoats++ : RejectedBoats++;


                    break;

                case 4:
                    Catamaran k = new Catamaran();


                    for (int i = 0; i < DockOne.Length; i += 2)
                    {
                        if (DockOne[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace == k.Slots)
                            {
                                Array.Fill(DockOne, k, i + 2 - k.Slots, k.Slots);
                                Boats.Add(k);
                                k.Docked = true;
                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    if (k.Docked == false)
                    {
                        avaliableSpace = 0;
                        for (int i = 0; i < DockTwo.Length; i += 2)
                        {
                            if (DockTwo[i] == null)
                            {
                                avaliableSpace += 2;
                                if (avaliableSpace == k.Slots)
                                {
                                    Array.Fill(DockTwo, k, i + 2 - k.Slots, k.Slots);
                                    Boats.Add(k);
                                    k.Docked = true;
                                    break;
                                }
                            }
                            else
                            {
                                avaliableSpace = 0;
                            }
                        }
                    }
                    _ = Boats.Contains(k) ? AddedBoats++ : RejectedBoats++;


                    break;

                case 5:
                    CargoShip c = new CargoShip();

                    for (int i = DockTwo.Length - 1; i > 0; i -= 2)
                    {
                        if (DockTwo[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace == c.Slots)
                            {
                                Array.Fill(DockTwo, c, i - 2 + 1, c.Slots);
                                Boats.Add(c);
                                c.Docked = true;

                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    if (c.Docked == false)
                    {
                        avaliableSpace = 0;
                        for (int i = DockOne.Length - 1; i > 0; i -= 2)
                        {
                            if (DockOne[i] == null)
                            {
                                avaliableSpace += 2;
                                if (avaliableSpace == c.Slots)
                                {
                                    Array.Fill(DockOne, c, i - 2 + 1, c.Slots);
                                    Boats.Add(c);
                                    c.Docked = true;

                                    break;
                                }
                            }
                            else
                            {
                                avaliableSpace = 0;
                            }
                        }
                    }
                    _ = Boats.Contains(c) ? AddedBoats++ : RejectedBoats++;

                    break;
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Adds a boat to the boat list.
 /// </summary>
 /// <param name="boat">The boat object to add to the boat list.</param>
 public void AddBoat(Boat boat)
 {
     Boats.Add(boat);
 }
Exemplo n.º 5
0
        public override void DoOperation()
        {
            try
            {
                //Validate Reques Header / Constants
                this.baseResponseMessage = ValidateInput();
                if (!this.baseResponseMessage.header.IsSuccess)
                {
                    throw new Exception(this.baseResponseMessage.header.ResponseMessage);
                }

                //Operation
                switch (this.request.Header.OperationTypes)
                {
                case (int)OperationType.OperationTypes.ADD:
                    #region ADD
                    long checkGuid = 0;
                    this.captain = new Captains
                    {
                        INSERT_USER         = this.request.INSERT_USER,
                        UPDATE_USER         = this.request.UPDATE_USER,
                        CAPTAIN_NAME        = this.request.CAPTAIN_NAME,
                        CAPTAIN_MIDDLE_NAME = this.request.CAPTAIN_MIDDLE_NAME,
                        CAPTAIN_SURNAME     = this.request.CAPTAIN_SURNAME,
                        BOAT_ID             = this.request.BOAT_ID,
                        IDENTIFICATION_ID   = this.request.IDENTIFICATION_ID,
                        EMAIL        = this.request.EMAIL,
                        PHONE_NUMBER = this.request.PHONE_NUMBER,
                        CAPTAIN_INFO = this.request.CAPTAIN_INFO
                    };
                    //Add Data to Database
                    checkGuid = captainsService.Insert(this.captain);

                    //Connect captain to related Boat
                    Boats boat = new Boats();
                    boat            = boatsService.SelectByBoatId(this.captain.BOAT_ID);
                    boat.CAPTAIN_ID = checkGuid;
                    boatsService.Update(boat);

                    this.response = new ResponseCaptain
                    {
                        CAPTAIN_ID          = checkGuid,
                        CAPTAIN_NAME        = this.request.CAPTAIN_NAME,
                        CAPTAIN_MIDDLE_NAME = this.request.CAPTAIN_MIDDLE_NAME,
                        CAPTAIN_SURNAME     = this.request.CAPTAIN_SURNAME,
                        BOAT_ID             = this.request.BOAT_ID,
                        IDENTIFICATION_ID   = this.request.IDENTIFICATION_ID,
                        EMAIL        = this.request.EMAIL,
                        PHONE_NUMBER = this.request.PHONE_NUMBER,
                        CAPTAIN_INFO = this.request.CAPTAIN_INFO,
                        header       = new ResponseHeader
                        {
                            IsSuccess       = checkGuid == 0 ? false : true,
                            ResponseCode    = checkGuid == 0 ? CommonDefinitions.INTERNAL_SYSTEM_UNKNOWN_ERROR : CommonDefinitions.SUCCESS,
                            ResponseMessage = checkGuid == 0 ? CommonDefinitions.ERROR_MESSAGE : CommonDefinitions.SUCCESS_MESSAGE
                        }
                    };
                    #endregion
                    break;

                case (int)OperationType.OperationTypes.UPDATE:
                    #region UPDATE
                    this.captain = new Captains
                    {
                        UPDATE_USER         = this.request.UPDATE_USER,
                        CAPTAIN_NAME        = this.request.CAPTAIN_NAME,
                        CAPTAIN_MIDDLE_NAME = this.request.CAPTAIN_MIDDLE_NAME,
                        CAPTAIN_SURNAME     = this.request.CAPTAIN_SURNAME,
                        BOAT_ID             = this.request.BOAT_ID,
                        IDENTIFICATION_ID   = this.request.IDENTIFICATION_ID,
                        EMAIL        = this.request.EMAIL,
                        PHONE_NUMBER = this.request.PHONE_NUMBER,
                        CAPTAIN_INFO = this.request.CAPTAIN_INFO
                    };
                    //Modify Data to Database
                    captainsService.Update(this.captain);
                    this.response = new ResponseCaptain
                    {
                        CAPTAIN_NAME        = this.request.CAPTAIN_NAME,
                        CAPTAIN_MIDDLE_NAME = this.request.CAPTAIN_MIDDLE_NAME,
                        CAPTAIN_SURNAME     = this.request.CAPTAIN_SURNAME,
                        BOAT_ID             = this.request.BOAT_ID,
                        IDENTIFICATION_ID   = this.request.IDENTIFICATION_ID,
                        EMAIL        = this.request.EMAIL,
                        PHONE_NUMBER = this.request.PHONE_NUMBER,
                        CAPTAIN_INFO = this.request.CAPTAIN_INFO,
                        header       = new ResponseHeader
                        {
                            IsSuccess       = true,
                            ResponseCode    = CommonDefinitions.SUCCESS,
                            ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                        }
                    };
                    #endregion
                    break;

                case (int)OperationType.OperationTypes.GET:
                    #region GET
                    //Get Data
                    this.captain = captainsService.SelectByBoatId(this.request.BOAT_ID);

                    this.response = new ResponseCaptain
                    {
                        CAPTAIN_NAME        = this.captain.CAPTAIN_NAME,
                        CAPTAIN_MIDDLE_NAME = this.captain.CAPTAIN_MIDDLE_NAME,
                        CAPTAIN_SURNAME     = this.captain.CAPTAIN_SURNAME,
                        BOAT_ID             = this.captain.BOAT_ID,
                        IDENTIFICATION_ID   = this.captain.IDENTIFICATION_ID,
                        EMAIL        = this.captain.EMAIL,
                        PHONE_NUMBER = this.captain.PHONE_NUMBER,
                        CAPTAIN_INFO = this.captain.CAPTAIN_INFO,
                        header       = new ResponseHeader
                        {
                            IsSuccess       = true,
                            ResponseCode    = CommonDefinitions.SUCCESS,
                            ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                        }
                    };
                    #endregion
                    break;

                case (int)OperationType.OperationTypes.DELETE:
                    #region DELETE
                    this.captain = captainsService.SelectByBoatId(this.request.BOAT_ID);

                    captainsService.Delete(this.captain);
                    this.response = new ResponseCaptain
                    {
                        CAPTAIN_NAME        = "",
                        CAPTAIN_MIDDLE_NAME = "",
                        CAPTAIN_SURNAME     = "",
                        BOAT_ID             = this.captain.BOAT_ID,
                        IDENTIFICATION_ID   = 0,
                        EMAIL        = "",
                        PHONE_NUMBER = "",
                        CAPTAIN_INFO = "",
                        header       = new ResponseHeader
                        {
                            IsSuccess       = true,
                            ResponseCode    = CommonDefinitions.SUCCESS,
                            ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                        }
                    };

                    //DisConnect captain to related Boat
                    Boats boats = new Boats();
                    boats            = boatsService.SelectByBoatId(this.captain.BOAT_ID);
                    boats.CAPTAIN_ID = 0;
                    boatsService.Update(boats);

                    #endregion
                    break;


                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                string operationError = "HATA:[" + "CaptainId:" + this.request.CAPTAIN_ID + ",ResponseCode:" + this.baseResponseMessage.header.ResponseCode + ", ResponseMessage:" + ex.Message + "]";
                log.InfoFormat(operationError, ex);
                throw new Exception(ex.Message, ex.InnerException);
            }
        }
Exemplo n.º 6
0
        public void DeleteBoat(int id)
        {
            Boat boat = Boats.Find(x => x.Id == id);

            Boats.Remove(boat);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Removes a boat from the boat list.
 /// </summary>
 /// <param name="boat">The boat object to remove from the boat list.</param>
 public void RemoveBoat(Boat boat)
 {
     Boats.Remove(boat);
 }
Exemplo n.º 8
0
        public void GenerateBoat(int amount)
        {
            for (int boat = 0; boat < amount; boat++)
            {
                int avaliableSpace = 0;

                switch (Rand.Next(1, 5 + 1))
                {
                case 1:
                    SailBoat s = new SailBoat();


                    for (int i = 0; i < Docks.Length; i += 2)
                    {
                        if (Docks[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace > s.Slots)
                            {
                                TempInterval = i - s.Slots;
                                Array.Fill(Docks, s, TempInterval, s.Slots);
                                Boats.Add(s);
                                s.Docked = true;

                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    _ = Boats.Contains(s) ? AddedBoats++ : RejectedBoats++;


                    break;

                case 2:
                    RowingBoat r = new RowingBoat();


                    for (int i = 0; i < Docks.Length; i++)
                    {
                        if (Docks[i] == null)
                        {
                            Array.Fill(Docks, r, i, r.Slots);
                            Boats.Add(r);
                            r.Docked = true;
                            break;
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    _ = Boats.Contains(r) ? AddedBoats++ : RejectedBoats++;


                    break;

                case 3:
                    PowerBoat p = new PowerBoat();


                    for (int i = 0; i < Docks.Length; i += 2)
                    {
                        if (Docks[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace > p.Slots)
                            {
                                TempInterval = i - p.Slots;
                                Array.Fill(Docks, p, TempInterval, p.Slots);
                                Boats.Add(p);
                                p.Docked = true;
                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    _ = Boats.Contains(p) ? AddedBoats++ : RejectedBoats++;


                    break;

                case 4:
                    Catamaran k = new Catamaran();


                    for (int i = 0; i < Docks.Length; i += 2)
                    {
                        if (Docks[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace > k.Slots)
                            {
                                TempInterval = i - k.Slots;
                                Array.Fill(Docks, k, TempInterval, k.Slots);
                                Boats.Add(k);
                                k.Docked = true;
                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    _ = Boats.Contains(k) ? AddedBoats++ : RejectedBoats++;


                    break;

                case 5:
                    CargoShip c = new CargoShip();

                    for (int i = Docks.Length - 1; i > 0; i -= 2)
                    {
                        if (Docks[i] == null)
                        {
                            avaliableSpace += 2;
                            if (avaliableSpace > c.Slots)
                            {
                                TempInterval = i + 1;
                                Array.Fill(Docks, c, TempInterval, c.Slots);
                                Boats.Add(c);
                                c.Docked = true;

                                break;
                            }
                        }
                        else
                        {
                            avaliableSpace = 0;
                        }
                    }
                    _ = Boats.Contains(c) ? AddedBoats++ : RejectedBoats++;

                    break;
                }
            }
        }
Exemplo n.º 9
0
        public void ReadDockData()
        {
            if (File.Exists(DataPath))
            {
                Data = File.ReadAllText(DataPath);
            }
            else
            {
                File.Create(DataPath);
            }

            if (Data == "")
            {
                Console.WriteLine("Harbour hasn't been opened yet...");
            }
            else
            {
                string[] split = Data.Split('\n');

                foreach (var item in split)
                {
                    if (item == split[0])
                    {
                        string[] counters = item.Split('-');
                        Day           = int.Parse(counters[0]);
                        RejectedBoats = int.Parse(counters[1]);
                        AddedBoats    = int.Parse(counters[2]);
                    }
                    else
                    {
                        string[] boats = item.Split(',');

                        if (boats[0].ToLower() == "sailboat" && !Array.Exists(Docks, b => b != null && b.ID == boats[1]))
                        {
                            SailBoat sail = new SailBoat()
                            {
                                ID           = boats[1],
                                Weight       = int.Parse(boats[2]),
                                MaxSpeed     = int.Parse(boats[3]),
                                LengthInFeet = int.Parse(boats[4]),
                                DaysDocked   = int.Parse(boats[5])
                            };
                            sail.Docked = true;
                            Array.Fill(Docks, sail, Counter, sail.Slots);
                            Boats.Add(sail);
                        }
                        if (boats[0].ToLower() == "rowingboat" && !Array.Exists(Docks, b => b != null && b.ID == boats[1]))
                        {
                            RowingBoat row = new RowingBoat()
                            {
                                ID           = boats[1],
                                Weight       = int.Parse(boats[2]),
                                MaxSpeed     = int.Parse(boats[3]),
                                MaxPassenger = int.Parse(boats[4]),
                                DaysDocked   = int.Parse(boats[5])
                            };
                            row.Docked = true;

                            Array.Fill(Docks, row, Counter, row.Slots);
                            Boats.Add(row);
                        }
                        if (boats[0].ToLower() == "powerboat" && !Array.Exists(Docks, b => b != null && b.ID == boats[1]))
                        {
                            PowerBoat power = new PowerBoat()
                            {
                                ID                 = boats[1],
                                Weight             = int.Parse(boats[2]),
                                MaxSpeed           = int.Parse(boats[3]),
                                NumberOfHorsepower = int.Parse(boats[4]),
                                DaysDocked         = int.Parse(boats[5])
                            };
                            power.Docked = true;

                            Array.Fill(Docks, power, Counter, power.Slots);
                            Boats.Add(power);
                        }
                        if (boats[0].ToLower() == "catamaran" && !Array.Exists(Docks, b => b != null && b.ID == boats[1]))
                        {
                            Catamaran catamaran = new Catamaran()
                            {
                                ID         = boats[1],
                                Weight     = int.Parse(boats[2]),
                                MaxSpeed   = int.Parse(boats[3]),
                                Beds       = int.Parse(boats[4]),
                                DaysDocked = int.Parse(boats[5])
                            };
                            catamaran.Docked = true;

                            Array.Fill(Docks, catamaran, Counter, catamaran.Slots);
                            Boats.Add(catamaran);
                        }
                        if (boats[0].ToLower() == "cargoship" && !Array.Exists(Docks, b => b != null && b.ID == boats[1]))
                        {
                            CargoShip cargo = new CargoShip()
                            {
                                ID              = boats[1],
                                Weight          = int.Parse(boats[2]),
                                MaxSpeed        = int.Parse(boats[3]),
                                CargoContainers = int.Parse(boats[4]),
                                DaysDocked      = int.Parse(boats[5])
                            };
                            cargo.Docked = true;

                            Array.Fill(Docks, cargo, Counter, cargo.Slots);
                            Boats.Add(cargo);
                        }

                        Counter++;
                    }
                }
                Counter = 0;
            }
        }
Exemplo n.º 10
0
        public override void DoOperation()
        {
            //Validate Reques Header / Constants
            this.baseResponseMessage = ValidateInput();
            if (!this.baseResponseMessage.header.IsSuccess)
            {
                throw new Exception(this.baseResponseMessage.header.ResponseMessage);
            }

            switch (this.request.Header.OperationTypes)
            {
            case (int)OperationType.OperationTypes.ADD:
                #region ADD
                Int32 capacity = 0;
                Boats boat     = new Boats();
                boat = Boats.SelectByBoatId(request.BOAT_ID);
                if (Convert.ToInt32(request.CAPACITY) < boat.QUANTITY)
                {
                    capacity = boat.QUANTITY - Convert.ToInt32(request.CAPACITY);
                }
                else
                {
                    throw new Exception(CommonDefinitions.BOAT_CAPACITY_IS_NOT_ENOUGH);
                }

                boatCapacity = new BoatsCapacity
                {
                    BOAT_ID              = request.BOAT_ID,
                    CAPACITY             = request.CAPACITY,
                    RESERVATION_DATE     = request.RESERVATION_DATE,
                    RESERVATION_END_DATE = request.RESERVATION_END_DATE,
                    RESERVATION_ID       = request.RESERVATION_ID
                };

                BoatsCapacity responseBoatsCapacity = new BoatsCapacity();
                responseBoatsCapacity = BoatsCapacity.SelectByBoatId(boatCapacity);
                if (responseBoatsCapacity == null)
                {
                    boatCapacity.CAPACITY = capacity.ToString();

                    boatCapacity.BOAT_CAPACITY_ID = BoatsCapacity.Insert(boatCapacity);
                }
                else
                {
                    responseBoatsCapacity.RESERVATION_ID = boatCapacity.RESERVATION_ID;
                    Int32 newCapactiy = Convert.ToInt32(response.CAPACITY) - Convert.ToInt32(boatCapacity.CAPACITY);
                    if (newCapactiy < 0)
                    {
                        throw new Exception(CommonDefinitions.BOAT_CAPACITY_IS_NOT_ENOUGH);
                    }
                    else
                    {
                        response.CAPACITY = newCapactiy.ToString();
                        BoatsCapacity.Update(responseBoatsCapacity);
                    }
                }

                this.response = new ResponseBoatCapacity
                {
                    BOAT_ID              = responseBoatsCapacity.BOAT_ID,
                    CAPACITY             = responseBoatsCapacity.CAPACITY,
                    RESERVATION_DATE     = responseBoatsCapacity.RESERVATION_DATE,
                    RESERVATION_END_DATE = responseBoatsCapacity.RESERVATION_END_DATE,
                    RESERVATION_ID       = responseBoatsCapacity.RESERVATION_ID,
                    BOAT_CAPACITY_ID     = responseBoatsCapacity.BOAT_CAPACITY_ID,
                    header = new ResponseHeader
                    {
                        IsSuccess       = true,
                        ResponseCode    = CommonDefinitions.SUCCESS,
                        ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                    }
                };
                #endregion
                break;

            case (int)OperationType.OperationTypes.GET:
                #region Get
                boatCapacity = new BoatsCapacity
                {
                    BOAT_ID              = request.BOAT_ID,
                    CAPACITY             = request.CAPACITY,
                    RESERVATION_DATE     = request.RESERVATION_DATE,
                    RESERVATION_END_DATE = request.RESERVATION_END_DATE,
                    RESERVATION_ID       = request.RESERVATION_ID
                };

                BoatsCapacity responseCapacity = new BoatsCapacity();
                responseCapacity = BoatsCapacity.SelectByBoatId(boatCapacity);

                this.response = new ResponseBoatCapacity
                {
                    BOAT_ID              = responseCapacity.BOAT_ID,
                    CAPACITY             = responseCapacity.CAPACITY,
                    RESERVATION_DATE     = responseCapacity.RESERVATION_DATE,
                    RESERVATION_END_DATE = responseCapacity.RESERVATION_END_DATE,
                    RESERVATION_ID       = responseCapacity.RESERVATION_ID,
                    BOAT_CAPACITY_ID     = responseCapacity.BOAT_CAPACITY_ID,
                    header = new ResponseHeader
                    {
                        IsSuccess       = true,
                        ResponseCode    = CommonDefinitions.SUCCESS,
                        ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                    }
                };
                #endregion
                break;

            default:
                break;
            }
        }
Exemplo n.º 11
0
        public IActionResult Index()
        {
            var boatInfo = new Boats();

            return(View(boatInfo._NextClosing));
        }
Exemplo n.º 12
0
        /// <summary>
        /// Checks if parsed boats are correct and connects them to the BattleField in the case of success
        /// </summary>
        /// <param name="p_message">Error string</param>
        /// <returns>returns true if arrangement was correct</returns>
        public bool CheckArrangement(out string p_message)
        {
            // 3. Check if Boats are correct

            bool _result = true;

            //first check quantity

            if (Boats != null)
            {
                if (Boats.All(b => (b.Cells.Select(c => c.x).Distinct().Count() == 1) ||
                              (b.Cells.Select(c => c.y).Distinct().Count() == 1)
                              )
                    )
                {
                    if (Boats.Count == 10)
                    {
                        if (Boats.All(a => a.Cells.Count <= 4))
                        {
                            if (
                                Boats.Count(a => a.Cells.Count == 4) == 1 &&
                                Boats.Count(a => a.Cells.Count == 3) == 2 &&
                                Boats.Count(a => a.Cells.Count == 2) == 3 &&
                                Boats.Count(a => a.Cells.Count == 1) == 4
                                )
                            {
                                _result   = true;
                                p_message = "The Boats arranged correctly";
                            }
                            else
                            {
                                _result   = false;
                                p_message = "Wrong set of Boats";
                            }
                        }
                        else
                        {
                            _result   = false;
                            p_message = "Some Boats are too long";
                        }
                    }
                    else
                    {
                        _result   = false;
                        p_message = "Incorrect quantity of Boats";
                    }
                }
                else
                {
                    _result   = false;
                    p_message = "A Boat can't bend or touch an other Boat diagonally";
                }
            }
            else
            {
                throw new Exception("Before Check the Boats should be parsed");
            }


            if (_result)
            {
                foreach (var boat in Boats)
                {
                    this.ConnectBoatToBF(boat);
                }
            }
            return(_result);
        }
Exemplo n.º 13
0
        public string GetFiredAtMessage(string input)
        {
            input = input.Split(' ')[1].ToUpper();
            var boatName = "";
            var boatEnum = 0;
            var sunk     = true;

            if (!GetFiredAt(input))
            {
                return(StatusCode.Miss.GetDescription());
            }

            foreach (var boat in Boats)
            {
                foreach (var coor in boat.Coordinates)
                {
                    if (coor.Key == input)
                    {
                        boatName = boat.Name;
                    }
                }
            }

            foreach (var boat in Boats)
            {
                foreach (var coor in boat.Coordinates)
                {
                    if (boat.Name == boatName && coor.Value == false)
                    {
                        sunk = false;
                    }
                }

                if (boat.Name == boatName && sunk)
                {
                    boat.Alive = false;
                }
            }

            if (Boats.All(x => x.Alive == false))
            {
                // WON
                return(StatusCode.YouWin.GetDescription());
            }


            // SUNK
            if (sunk)
            {
                switch (boatName)
                {
                case "Carrier":
                    boatEnum = 251;
                    break;

                case "Battleship":
                    boatEnum = 252;
                    break;

                case "Destroyer":
                    boatEnum = 253;
                    break;

                case "Submarine":
                    boatEnum = 254;
                    break;

                case "Patrol Boat":
                    boatEnum = 255;
                    break;
                }
            }
            else
            {
                // HIT
                switch (boatName)
                {
                case "Carrier":
                    boatEnum = 241;
                    break;

                case "Battleship":
                    boatEnum = 242;
                    break;

                case "Destroyer":
                    boatEnum = 243;
                    break;

                case "Submarine":
                    boatEnum = 244;
                    break;

                case "Patrol Boat":
                    boatEnum = 245;
                    break;
                }
            }

            var myEnum = (StatusCode)boatEnum;

            return(myEnum.GetDescription());
        }
Exemplo n.º 14
0
        /// <summary>
        /// Adds boats to the race db. Runs logic for for whether they have crew or not.
        /// </summary>
        /// <param name="boat"></param>
        public static void SetBoats(Boats boat)
        {
            using (IDbConnection connection = new MySql.Data.MySqlClient.MySqlConnection(Helper.CnnVal()))
            {
                // If they don't have crew remove single.
                if (Program.Globals.Crew == null)
                {
                    // Try to add them.
                    try
                    {
                        InsertInto(boat, 0);
                    }

                    // Else add new DB for new race then add them
                    catch
                    {
                        var sql = new StringBuilder();
                        sql.Append("CREATE TABLE if not exists  ");
                        sql.Append(_race);
                        sql.Append(
                            " (`name` varchar(50) NOT NULL,`boat` varchar(50) DEFAULT NULL," +
                            "`boatNumber` int(11) DEFAULT NULL," +
                            "`crew` int(1) DEFAULT NULL,PRIMARY KEY(`name`)) ENGINE = InnoDB DEFAULT CHARSET" +
                            " = utf8mb4;");
                        connection.Execute(sql.ToString());
                        InsertInto(boat, 0);
                    }
                }

                //Else remove both.
                else
                {
                    // Try to add one person.
                    try
                    {
                        InsertInto(boat, 0);
                    }

                    // Else create db and then add person.
                    catch
                    {
                        var sql = new StringBuilder();
                        sql.Append("CREATE TABLE if not exists  ");
                        sql.Append(_race);
                        sql.Append(
                            " (`name` varchar(50) NOT NULL,`boat` varchar(50) DEFAULT NULL," +
                            "`boatNumber` int(11) DEFAULT NULL," +
                            "`crew` int(1) DEFAULT NULL,PRIMARY KEY(`name`)) ENGINE = InnoDB DEFAULT CHARSET" +
                            " = utf8mb4;");
                        connection.Execute(sql.ToString());
                        InsertInto(boat, 0);
                    }

                    // In every case we will add the second without fail.
//                    finally
//                    {

                    var boats1 = new Boats(Program.Globals.Crew, boat.BoatName, boat.BoatNumber);
                    InsertInto(boats1, 1);

//                    }
                }
            }
        }
        private void CreateBoats()
        {
            foreach (IBoat boat in Boats)
            {
                BoatControl boatControl = new BoatControl();

                Binding height = new Binding(nameof(BoatControl.BoatHeightProperty))
                {
                    Source = boat,
                    Path   = new PropertyPath("RowSpan")
                };

                Binding width = new Binding(nameof(BoatControl.BoatWidthProperty))
                {
                    Source = boat,
                    Path   = new PropertyPath("ColumnSpan")
                };

                Binding column = new Binding(nameof(ColumnProperty))
                {
                    Source = boat,
                    Path   = new PropertyPath("Column")
                };

                Binding row = new Binding(nameof(RowProperty))
                {
                    Source = boat,
                    Path   = new PropertyPath("Row")
                };

                Binding columnSpan = new Binding(nameof(ColumnSpanProperty))
                {
                    Source = boat,
                    Path   = new PropertyPath("ColumnSpan")
                };

                Binding rowSpan = new Binding(nameof(RowSpanProperty))
                {
                    Source = boat,
                    Path   = new PropertyPath("RowSpan")
                };

                Binding isSelected = new Binding(nameof(BoatControl.IsSelectedProperty))
                {
                    Source = boat,
                    Path   = new PropertyPath("IsSelected")
                };

                Binding isEnabled = new Binding(nameof(BoatControl.ShowBoat))
                {
                    Source = boat,
                    Path   = new PropertyPath("ShowItem")
                };

                boatControl.SetBinding(BoatControl.BoatHeightProperty, height);
                boatControl.SetBinding(BoatControl.BoatWidthProperty, width);
                boatControl.SetBinding(ColumnProperty, column);
                boatControl.SetBinding(RowProperty, row);
                boatControl.SetBinding(ColumnSpanProperty, columnSpan);
                boatControl.SetBinding(RowSpanProperty, rowSpan);
                boatControl.SetBinding(BoatControl.IsSelectedProperty, isSelected);
                boatControl.SetBinding(BoatControl.ShowBoatProperty, isEnabled);

                /// <summary>
                /// sets the first boat ontop of the board
                /// e.g. Boats[1] is the 2nd boat and there are 5 boats: 5 - 2 + 1 = 4
                /// hence the 4th highest of all the boats, "+ 1" is to be ontop of the checkered tiles
                /// </summary>
                Panel.SetZIndex(boatControl, Boats.Count - Boats.IndexOf(boat) + 1);
                BoardGrid.Children.Add(boatControl);
            }
        }
Exemplo n.º 16
0
        static void Main1(string[] args)
        {
            //Boats boat1 = new Boats("Adrian Stanislaus", 2, "Laser Stratos", 927, "Laser", 182782);
            //Boats boat2 = new Boats("Luke Stanislaus", 1, "Laser Stratos", 182782, null, 0);
            //Boats boat3 = new Boats("Simon Clark", 2, "Phantom", 1080, "Laser", 1234);


            Dictionary <string, Boats>       boatDictionary = new Dictionary <string, Boats>();
            Dictionary <string, BoatsRacing> raceDictionary = new Dictionary <string, BoatsRacing>();
            //boatDictionary.Add("hi", boat1);
            //Console.WriteLine("Enter path to folder of files.");
            //string path = Console.ReadLine();
            //boatDictionary = LoadFullFile(path);
            //List<Boats> boat = new Dictionary<string, Boats>();
            List <BoatsRacing> raceList = new List <BoatsRacing>();

            //Console.WriteLine("Enter path to folder of files");
            string[] path1 = System.Reflection.Assembly.GetEntryAssembly().Location.Split(char.Parse(@"\"));
            string   path  = "";
            int      b     = 0;

            while (path1[b] != "Sailing2")
            {
                path = string.Concat(path + path1[b] + @"\Data\");
                b++;
            }
            //string path2 = path.Split(path)

            /*
             * Console.WriteLine("Enter name");
             * string name1 = Console.ReadLine();
             * LoadFullSQL db = new LoadFullSQL();
             * boatlist = db.GetBoats();
             * Console.WriteLine(db.GetBoat(name1).boat1);
             */
            //boatDictionary = LoadFullSQL.getdictionary(boatlist);

            /*
             * Console.WriteLine("Enter name");
             * string name2 = Console.ReadLine();
             * Console.WriteLine("Enter boatname");
             * string boatname2 = Console.ReadLine();
             * Console.WriteLine("Enter boatnumber");
             * int boatnumber2 = int.Parse(Console.ReadLine());
             * if (LoadFullSQL.AddBoat(name2, boatname2, boatnumber2) == true)
             *  Console.WriteLine("Success");
             * else
             *  Console.WriteLine("Fail");
             */
            //boatDictionary = LoadFullFile.loadFullFile(path);

            //Console.WriteLine(boatDictionary["Adrian Stanislaus"].boat1);
            //string hi = LoadFullFile();
            //Console.WriteLine(boatDictionary["Abc"].name);
            //boatDictionary.Add(boat1.name, boat1);
            //boatDictionary.Add(boat2.name, boat2);
            //boatDictionary.Add(boat3.name, boat3);
            //LoadFullFile.ExportToFile(boatDictionary, path);

            while (true)
            {
                Console.WriteLine("Who is it?");
                string person = Console.ReadLine();
                try
                {
                    LoadFullSQL db1 = new LoadFullSQL();
                    //Boats personboat = db1.GetBoat(person);
                    Boats personboat = db1.GetBoat(person);
                    while (person == personboat.name)
                    {
                        if (personboat.noOfBoats > 0)
                        {
                            Console.WriteLine("Is your boat a(n) {0}, Y/N?", personboat.boat1);
                            string response = Console.ReadLine();
                            if (response == "Y" || response == "y")
                            {
                                //BoatsRacing.converter1(personboat);
                                LoadFullSQL.SQLaddnewracer(personboat, BoatsRacing.converter1(personboat));
                                Console.ReadLine();

                                break;
                            }
                            else if (personboat.noOfBoats == 1)
                            {
                                LoadFullSQL.AddBoat(personboat);
                            }
                        }
                        if (personboat.noOfBoats > 1)
                        {
                            Console.WriteLine("Is your boat a(n) {0}, Y/N?", personboat.boat2);
                            string response = Console.ReadLine();
                            if (response == "Y" || response == "y")
                            {
                                LoadFullSQL.SQLaddnewracer(personboat, BoatsRacing.converter1(personboat));
                                Console.ReadLine();
                                break;
                            }
                            else if (personboat.noOfBoats == 2)
                            {
                                LoadFullSQL.AddBoat(personboat);
                            }
                        }
                        if (personboat.noOfBoats > 2)
                        {
                            Console.WriteLine("Is your boat a(n) {0}, Y/N?", personboat.boat3);
                            string response = Console.ReadLine();
                            if (response == "Y" || response == "y")
                            {
                                LoadFullSQL.SQLaddnewracer(personboat, BoatsRacing.converter1(personboat));
                                Console.ReadLine();
                                break;
                            }
                            else if (personboat.noOfBoats == 3)
                            {
                                LoadFullSQL.AddBoat(personboat);
                            }
                        }
                        if (personboat.noOfBoats > 3)
                        {
                            Console.WriteLine("Is your boat a(n) {0}, Y/N?", personboat.boat4);
                            string response = Console.ReadLine();
                            if (response == "Y" || response == "y")
                            {
                                LoadFullSQL.SQLaddnewracer(personboat, BoatsRacing.converter1(personboat));
                                Console.ReadLine();
                                break;
                            }
                            else if (personboat.noOfBoats == 4)
                            {
                                LoadFullSQL.AddBoat(personboat);
                            }
                        }
                        if (personboat.noOfBoats > 4)
                        {
                            Console.WriteLine("Is your boat a(n) {0}, Y/N?", personboat.boat5);
                            string response = Console.ReadLine();
                            if (response == "Y" || response == "y")
                            {
                                LoadFullSQL.SQLaddnewracer(personboat, BoatsRacing.converter1(personboat));
                                Console.ReadLine();
                                break;
                            }
                            else if (personboat.noOfBoats == 5)
                            {
                                LoadFullSQL.AddBoat(personboat);
                            }
                        }
                        Console.Clear();
                        personboat = db1.GetBoat(person);
                    }
                }

                catch (KeyNotFoundException)
                {
                }
                //Dictionary<string, Boats> nothing = new Dictionary<string, Boats>();
                //boatDictionary = LoadFullFile.loadFullFile(path);
                //string hi2 = LoadFullFile();
                Console.Clear();
                Console.WriteLine("Escape, Y/N?");
                if (Console.ReadLine() == "y" || Console.ReadLine() == "Y")
                {
                    break;
                }
            }
            foreach (var item in raceList)
            {
                Console.WriteLine("Name = {0}, BoatName = {1}, BoatNumber = {2}", item.name, item.boatName, item.boatNumber);
            }
            Console.ReadLine();

            /*
             * Console.WriteLine("Would you like to remove a boat?");
             * if (Console.ReadLine() == "y" || Console.ReadLine() == "Y")
             * {
             *  LoadFullSQL.SQLremoveboat()
             * }
             */
        }
Exemplo n.º 17
0
        public override void DoOperation()
        {
            try
            {
                //Validate Reques Header / Constants
                this.baseResponseMessage = ValidateInput();
                if (!this.baseResponseMessage.header.IsSuccess)
                {
                    throw new Exception(this.baseResponseMessage.header.ResponseMessage);
                }

                switch (this.request.Header.OperationTypes)
                {
                case (int)OperationType.OperationTypes.ADD:
                    #region Add
                    long checkGuid = 0;
                    this.boat = new Boats
                    {
                        INSERT_USER   = this.request.INSERT_USER,
                        UPDATE_USER   = this.request.UPDATE_USER,
                        BOAT_INFO     = this.request.BOAT_INFO,
                        BOAT_NAME     = this.request.BOAT_NAME,
                        CAPTAIN_ID    = this.request.CAPTAIN_ID,
                        FLAG          = this.request.FLAG,
                        QUANTITY      = this.request.QUANTITY,
                        ROTA_INFO     = this.request.ROTA_INFO,
                        REGION_ID     = this.request.REGION_ID,
                        PRICE         = this.request.PRICE,
                        PRIVATE_PRICE = this.request.PRIVATE_PRICE,
                        TOUR_TYPE     = this.request.TOUR_TYPE
                    };

                    checkGuid = Boats.Insert(this.boat);

                    this.response = new ResponseBoats
                    {
                        INSERT_USER   = this.boat.INSERT_USER,
                        UPDATE_USER   = this.boat.UPDATE_USER,
                        BOAT_ID       = this.boat.BOAT_ID,
                        BOAT_INFO     = this.boat.BOAT_INFO,
                        BOAT_NAME     = this.boat.BOAT_NAME,
                        CAPTAIN_ID    = this.request.CAPTAIN_ID,
                        FLAG          = this.request.FLAG,
                        QUANTITY      = this.request.QUANTITY,
                        ROTA_INFO     = this.request.ROTA_INFO,
                        REGION_ID     = this.request.REGION_ID,
                        REGION_NAME   = CommonServices.GetRegionName(this.request.REGION_ID),
                        PRICE         = this.request.PRICE,
                        PRIVATE_PRICE = this.request.PRIVATE_PRICE,
                        TOUR_TYPE     = this.request.TOUR_TYPE,
                        header        = new ResponseHeader
                        {
                            IsSuccess       = checkGuid == 0 ? false : true,
                            ResponseCode    = checkGuid == 0 ? CommonDefinitions.INTERNAL_SYSTEM_UNKNOWN_ERROR : CommonDefinitions.SUCCESS,
                            ResponseMessage = checkGuid == 0 ? CommonDefinitions.ERROR_MESSAGE : CommonDefinitions.SUCCESS_MESSAGE
                        }
                    };
                    #endregion
                    break;

                case (int)OperationType.OperationTypes.GET:
                    #region GET
                    //Bölgesel Arama
                    if (this.request.REGION_ID != 0)
                    {
                        this.listboat = Boats.SelectByRegionId(this.request.REGION_ID);
                        if (listboat != null && listboat.Count > 0)
                        {
                            foreach (var item in listboat)
                            {
                                this.response = new ResponseBoats
                                {
                                    INSERT_USER = item.INSERT_USER,
                                    UPDATE_USER = item.UPDATE_USER,
                                    BOAT_ID     = item.BOAT_ID,
                                    BOAT_INFO   = item.BOAT_INFO,
                                    BOAT_NAME   = item.BOAT_NAME,
                                    CAPTAIN_ID  = item.CAPTAIN_ID,
                                    FLAG        = item.FLAG,
                                    QUANTITY    = item.QUANTITY,
                                    ROTA_INFO   = item.ROTA_INFO,
                                    REGION_ID   = item.REGION_ID,
                                    REGION_NAME = CommonServices.GetRegionName(this.request.REGION_ID),
                                    header      = new ResponseHeader
                                    {
                                        IsSuccess       = true,
                                        ResponseCode    = CommonDefinitions.SUCCESS,
                                        ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                                    }
                                };
                                reponseAllBoats.Add(this.response);
                            }
                            this.response.AllBoats = reponseAllBoats;
                        }
                    }
                    else
                    {
                        //Tekli Arama
                        this.boat = Boats.SelectByBoatId(this.request.BOAT_ID);

                        this.response = new ResponseBoats
                        {
                            INSERT_USER = this.boat.INSERT_USER,
                            UPDATE_USER = this.boat.UPDATE_USER,
                            BOAT_ID     = this.boat.BOAT_ID,
                            BOAT_INFO   = this.boat.BOAT_INFO,
                            BOAT_NAME   = this.boat.BOAT_NAME,
                            CAPTAIN_ID  = this.boat.CAPTAIN_ID,
                            FLAG        = this.boat.FLAG,
                            QUANTITY    = this.boat.QUANTITY,
                            ROTA_INFO   = this.boat.ROTA_INFO,
                            REGION_ID   = this.boat.REGION_ID,
                            REGION_NAME = CommonServices.GetRegionName(this.request.REGION_ID),
                            header      = new ResponseHeader
                            {
                                IsSuccess       = true,
                                ResponseCode    = CommonDefinitions.SUCCESS,
                                ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                            }
                        };
                    }
                    #endregion
                    break;

                case (int)OperationType.OperationTypes.UPDATE:
                    #region  Update
                    this.boat = new Boats
                    {
                        BOAT_ID       = this.request.BOAT_ID,
                        INSERT_USER   = this.request.INSERT_USER,
                        UPDATE_USER   = this.request.UPDATE_USER,
                        BOAT_INFO     = this.request.BOAT_INFO,
                        BOAT_NAME     = this.request.BOAT_NAME,
                        CAPTAIN_ID    = this.request.CAPTAIN_ID,
                        FLAG          = this.request.FLAG,
                        QUANTITY      = this.request.QUANTITY,
                        ROTA_INFO     = this.request.ROTA_INFO,
                        REGION_ID     = this.request.REGION_ID,
                        PRICE         = this.request.PRICE,
                        PRIVATE_PRICE = this.request.PRIVATE_PRICE,
                        TOUR_TYPE     = this.request.TOUR_TYPE
                    };

                    Boats.Update(this.boat);

                    this.response = new ResponseBoats
                    {
                        INSERT_USER = this.boat.INSERT_USER,
                        UPDATE_USER = this.boat.UPDATE_USER,
                        BOAT_ID     = this.boat.BOAT_ID,
                        BOAT_INFO   = this.boat.BOAT_INFO,
                        BOAT_NAME   = this.boat.BOAT_NAME,
                        CAPTAIN_ID  = this.boat.CAPTAIN_ID,
                        FLAG        = this.boat.FLAG,
                        QUANTITY    = this.boat.QUANTITY,
                        ROTA_INFO   = this.boat.ROTA_INFO,
                        REGION_ID   = this.boat.REGION_ID,
                        REGION_NAME = CommonServices.GetRegionName(this.request.REGION_ID),
                        header      = new ResponseHeader
                        {
                            IsSuccess       = true,
                            ResponseCode    = CommonDefinitions.SUCCESS,
                            ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                        }
                    };
                    #endregion
                    break;

                case (int)OperationType.OperationTypes.DELETE:
                    #region DELETE
                    this.boat = new Boats
                    {
                        INSERT_USER = this.request.INSERT_USER,
                        UPDATE_USER = this.request.UPDATE_USER,
                        BOAT_INFO   = this.request.BOAT_INFO,
                        BOAT_NAME   = this.request.BOAT_NAME,
                        CAPTAIN_ID  = this.request.CAPTAIN_ID,
                        FLAG        = this.request.FLAG,
                        QUANTITY    = this.request.QUANTITY,
                        ROTA_INFO   = this.request.ROTA_INFO,
                        REGION_ID   = this.request.REGION_ID
                    };

                    Boats.Delete(this.boat);
                    this.response = new ResponseBoats
                    {
                        INSERT_USER = this.boat.INSERT_USER,
                        UPDATE_USER = this.boat.UPDATE_USER,
                        BOAT_ID     = this.boat.BOAT_ID,
                        BOAT_INFO   = this.boat.BOAT_INFO,
                        BOAT_NAME   = this.boat.BOAT_NAME,
                        CAPTAIN_ID  = this.boat.CAPTAIN_ID,
                        FLAG        = this.boat.FLAG,
                        QUANTITY    = this.boat.QUANTITY,
                        ROTA_INFO   = this.boat.ROTA_INFO,
                        REGION_ID   = this.boat.REGION_ID,
                        REGION_NAME = CommonServices.GetRegionName(this.request.REGION_ID),
                        header      = new ResponseHeader
                        {
                            IsSuccess       = true,
                            ResponseCode    = CommonDefinitions.SUCCESS,
                            ResponseMessage = CommonDefinitions.SUCCESS_MESSAGE
                        }
                    };
                    #endregion
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                string operationError = "HATA:[" + "BoatId:" + this.request.BOAT_ID + ",ResponseCode:" + this.baseResponseMessage.header.ResponseCode + ", ResponseMessage:" + ex.Message + "]";
                log.InfoFormat(operationError, ex);
                throw new Exception(ex.Message, ex.InnerException);
            }
        }
Exemplo n.º 18
0
 public Boat GetBoat(int id)
 {
     return(Boats.Find(x => x.Id == id));
 }