Exemplo n.º 1
0
        private static void ShowPrices()
        {
            using (var DB = new Data.BoatBookingSystemEntities1())
            {
                var prices = DB.Prices.ToList();

                foreach (var p in prices)
                {
                    Console.WriteLine();
                    Console.WriteLine("***************************************************************");
                    Console.WriteLine(" PriceID: " + p.PriceID);
                    Console.WriteLine(" Grundavgift: " + p.BasicFee);
                    Console.WriteLine(" Timavgift: " + p.HourFee);
                    Console.WriteLine(" Grundavgift multipliceringssats liten båt: " + p.BasicPriceSmallBoatAlgorithm);
                    Console.WriteLine(" Grundavgift multipliceringssats stor båt: " + p.BasicPriceBigBoatAlgorithm);
                    Console.WriteLine(" Timavgift multipliceringssats liten båt: " + p.HourPriceSmallBoatAlgorithm);
                    Console.WriteLine(" Timavgift multipliceringssats stor båt: " + p.HourPriceBigBoatAlgorithm);
                    Console.WriteLine();
                    Console.WriteLine("***************************************************************");
                }

            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(" Återgå till meny - tryck valfri tangent");
            Console.ReadKey();
            ShowMenu();
        }
Exemplo n.º 2
0
        private static void GetPrices()
        {
            using (var DB = new Data.BoatBookingSystemEntities1())
            {
                var prices = DB.Prices.ToList();
                int counter = 0;

                foreach (var p in prices)
                {
                    Console.WriteLine();
                    Console.WriteLine("***************************************************************");
                    Console.WriteLine(" PriceID: " + p.PriceID);
                    Console.WriteLine(" Grundavgift: " + p.BasicFee);
                    Console.WriteLine(" Timavgift: " + p.HourFee);
                    Console.WriteLine(" Grundavgift multipliceringssats liten båt: " + p.BasicPriceSmallBoatAlgorithm);
                    Console.WriteLine(" Grundavgift multipliceringssats stor båt: " + p.BasicPriceBigBoatAlgorithm);
                    Console.WriteLine(" Timavgift multipliceringssats liten båt: " + p.HourPriceSmallBoatAlgorithm);
                    Console.WriteLine(" Timavgift multipliceringssats stor båt: " + p.HourPriceBigBoatAlgorithm);
                    Console.WriteLine();
                    Console.WriteLine("***************************************************************");

                    counter++;

                    if (counter == prices.Count())
                        break;
                }
            }
        }
Exemplo n.º 3
0
        public List <int> GetAllYourBookingsByPersonIdentityNumber(string personidentitynumber)
        {
            var bookingnumberlist = new List <int>();

            try
            {
                using (var DB = new Data.BoatBookingSystemEntities1())
                {
                    var bookings = DB.Bookings
                                   .Where(b => b.PersonNumber == personidentitynumber).OrderByDescending(b => b.DeliveyDateTime)
                                   .Select(b => b.BookingNumber)
                                   .ToList();

                    foreach (var booking in bookings)
                    {
                        bookingnumberlist.Add(booking);
                    }
                }
            }
            catch (Exception ex)
            {
                string.Format("We could not find your rent information because of \"{0}\" .", ex.Message);
            }
            return(bookingnumberlist);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get the bookingnumber by the PersonIdentyNumber
        /// </summary>

        public int CheckLatestRentByPersonIdentityNumber(string personidentitynumber)
        {
            try
            {
                using (var DB = new Data.BoatBookingSystemEntities1())
                {
                    var bookings = (from b in DB.Bookings
                                    join u in DB.Boats on b.BoatID equals u.BoatID
                                    join c in DB.Categories on u.CatID equals c.CatID
                                    where b.PersonNumber.Equals(personidentitynumber)
                                    orderby b.DeliveyDateTime descending
                                    select new
                    {
                        BookingNumber = b.BookingNumber,
                        BoatName = u.Name,
                        Category = c.Name,
                        OverFourtyFeet = c.OverSizeFourty,
                        DeliveryDate = b.DeliveyDateTime
                    }).FirstOrDefault();


                    bookingnumber = bookings.BookingNumber;
                }
                return(bookingnumber);
            }
            catch (Exception ex)
            {
                string.Format("We could not find your rent information because of \"{0}\" .", ex.Message);
                bookingnumber = 0;
                return(bookingnumber);
            }
        }
Exemplo n.º 5
0
        public static void CreateCategories()
        {
            var category = new Data.Category();

            {
                Console.Clear();
                GetCategories();
                Console.WriteLine();
                Console.WriteLine(" Är det säkert att du vill lägga till en ny kategori? skriv j/n");
                string exit = Console.ReadLine();
                if (exit == "n")
                {
                    ShowMenu();
                }
                else
                {
                    Console.WriteLine(" ================================");
                    Console.WriteLine(" Lägg till ny kategori");
                    Console.WriteLine(" ================================");
                    Console.Write("\r\n Kategorinamn: ");
                    category.Name = Console.ReadLine();
                    Console.Write("\r\n Är Storleken över eller lika med 40 fot? j/n: ");
                    string choice = Console.ReadLine();
                    if (choice == "j")
                    {
                        category.OverSizeFourty = true;
                    }
                    else
                    {
                        category.OverSizeFourty = false;
                    }

                    using (var DB = new Data.BoatBookingSystemEntities1())
                    {
                        try
                        {
                            DB.Categories.Add(category);
                            DB.SaveChanges();
                            var id = category.CatID;
                        }
                        catch (Exception ex)
                        {
                            Console.Write("The category could't be saved becouse of \"{0}\" .", ex.Message);

                        }
                    }
                }
            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(" Återgå till meny - tryck valfri tangent");
            Console.ReadKey();
            ShowMenu();
        }
Exemplo n.º 6
0
        private static void ShowCategories()
        {
            var booking = new Booking();
            List<Data.Category> categoryname = new List<Data.Category>();

            Console.Clear();
            Console.WriteLine("===============================");
            Console.WriteLine("Kategorier");
            Console.WriteLine("===============================");

            try
            {
                using (var DB = new Data.BoatBookingSystemEntities1())
                {
                    var categories = DB.Categories.ToList();

                    foreach (var r in categories)
                    {
                        Console.WriteLine("***************************************************************");
                        Console.WriteLine(" ID: " + r.CatID);
                        Console.WriteLine(" Namn: " + r.Name);

                        categoryname = booking.GetValuesForCategoryName();

                        foreach (var cat in categoryname)
                        {
                            if (cat.Name == r.Name && cat.OverSizeFourty == r.OverSizeFourty)
                            {
                                if (r.OverSizeFourty == true)
                                {
                                    Console.Write(" över eller lika med 40 tum.");
                                }
                                else
                                {
                                    Console.Write(" mindre än 40 tum.");
                                }
                            }
                        }

                        Console.WriteLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Can't find categories because of, \"{0}\" .", ex.Message);
            }

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(" Återgå till meny - tryck valfri tangent");
            Console.ReadKey();
            ShowMenu();
        }
Exemplo n.º 7
0
        /// <summary>
        /// Here we got the price of the rental of the boat.This method is for the test method.
        /// </summary>
        /// <param name="bookingnumber"></param>
        /// <returns></returns>

        public bool GetThePriceOfTheBoatRentForTesting(int bookingnumber)
        {
            DateTime deliveryTime;
            DateTime?returnTime;
            DateTime newReturnTime;
            TimeSpan duration;
            int      boatnumber;

            try
            {
                using (var DB = new Data.BoatBookingSystemEntities1())
                {
                    var booking = DB.Bookings.FirstOrDefault(x => x.BookingNumber.Equals(bookingnumber));

                    if (booking != null && booking.ReturnDateTime != null)
                    {
                        deliveryTime  = booking.DeliveyDateTime;
                        returnTime    = booking.ReturnDateTime;
                        newReturnTime = (DateTime)booking.ReturnDateTime;
                        duration      = newReturnTime.Subtract(deliveryTime);
                        var days = duration.Days;
                        if (days > 0)
                        {
                            days = days * 24;
                        }
                        var hours   = duration.Hours + days;
                        var minutes = duration.Minutes;
                        if (minutes >= 1)
                        {
                            hours += 1;
                        }
                        boatnumber = booking.BoatID;
                        GetRentalPrice(hours, boatnumber);
                        return(true);
                    }
                    else
                    {
                        string.Format("The price could't be delivered because there is no return datetime of this rental.");
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                string.Format("The price could't be delivered because of \"{0}\" .", ex.Message);
                return(false);
            }
        }
Exemplo n.º 8
0
        public List <Data.Category> GetValuesForCategoryName()
        {
            var catlist = new List <Data.Category>();

            using (var DB = new Data.BoatBookingSystemEntities1())
            {
                var categoryvalues = DB.Categories.ToList();

                foreach (var cat in categoryvalues)
                {
                    catlist.Add(new Data.Category {
                        Name = cat.Name, OverSizeFourty = cat.OverSizeFourty
                    });
                }

                return(catlist);
            }
        }
Exemplo n.º 9
0
        private static void ShowBoats()
        {
            List<Data.Category> categoryname = new List<Data.Category>();
            var booking = new Booking();
            var counter = 0;

            using (var DB = new Data.BoatBookingSystemEntities1())
            {
                var boats = DB.Boats.Join(DB.Categories, cat => cat.CatID, boat => boat.CatID, (boat, cat) => new { BoatID = boat.BoatID, BoatName = boat.Name, PriceID = boat.PriceID, CatName = cat.Name, SizeOver40Feets = cat.OverSizeFourty }).ToList();
                Console.Clear();

                foreach (var r in boats)
                {
                    Console.WriteLine("***************************************************************");
                    Console.WriteLine(" ID: " + r.BoatID);
                    Console.WriteLine(" Båtnamn: " + r.BoatName);
                    Console.Write(" Kategori: " + r.CatName);

                    categoryname = booking.GetValuesForCategoryName();

                    foreach (var cat in categoryname)
                    {
                        if (cat.Name == r.CatName && cat.OverSizeFourty == r.SizeOver40Feets)
                        {
                            if (r.SizeOver40Feets == true)
                            {
                                Console.WriteLine(" över eller lika med 40 tum.");
                            }
                            else
                            {
                                Console.WriteLine(" mindre än 40 tum.");
                            }
                        }

                    }
                    Console.WriteLine(" PrisID: " + r.PriceID);
                    counter++;
                    if (counter == boats.Count())
                        break;

                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// This method returns the number of hours in which the boat rent has taken into account the requirement to round the hours upwards due to excessive minutes.
        /// </summary>
        /// <param name="bookingnumber"></param>
        /// <returns></returns>
        public int GetNumebrOfHoursForTheRental(int bookingnumber)
        {
            DateTime deliveryTime;
            DateTime?returnTime;
            DateTime newReturnTime;
            TimeSpan duration;
            int      hours = 0;

            try
            {
                using (var DB = new Data.BoatBookingSystemEntities1())
                {
                    var booking = DB.Bookings.FirstOrDefault(x => x.BookingNumber.Equals(bookingnumber));


                    if (booking != null && booking.ReturnDateTime != null)
                    {
                        deliveryTime  = booking.DeliveyDateTime;
                        returnTime    = booking.ReturnDateTime;
                        newReturnTime = (DateTime)booking.ReturnDateTime;
                        duration      = newReturnTime.Subtract(deliveryTime);
                        var days = duration.Days;
                        if (days > 0)
                        {
                            days = days * 24;
                        }
                        hours = duration.Hours + days;
                        var minutes = duration.Minutes;
                        if (minutes >= 1)
                        {
                            hours += 1;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string.Format("The hours could't be delivered because of \"{0}\" .", ex.Message);
            }
            return(hours);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Here we find out were wich the latest booking is for a specific person.
        /// </summary>
        /// <param name="personidentitynumber"></param>
        /// <returns></returns>

        public int LatestBookingNumberByPersonIdentityNumber(string personidentitynumber)
        {
            try
            {
                using (var DB = new Data.BoatBookingSystemEntities1())
                {
                    var bookings = DB.Bookings
                                   .Where(b => b.PersonNumber == personidentitynumber).OrderByDescending(b => b.DeliveyDateTime)
                                   .Select(b => b.BookingNumber)
                                   .FirstOrDefault();

                    bookingnumber = bookings;
                }
                return(bookingnumber);
            }
            catch (Exception ex)
            {
                string.Format("We could not find your rent information because of \"{0}\" .", ex.Message);
                bookingnumber = 0;
                return(bookingnumber);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// You know the booking number when you return the boat, and the returndate stores in the database.
        /// </summary>


        public bool ReturnBoatByBookingNumber(int bookingnumber)
        {
            try
            {
                using (var DB = new Data.BoatBookingSystemEntities1())
                {
                    var booking = DB.Bookings.FirstOrDefault(x => x.BookingNumber.Equals(bookingnumber));

                    if (booking != null)
                    {
                        booking.ReturnDateTime = DateTime.Now;
                    }
                    DB.Entry(booking).State = System.Data.Entity.EntityState.Modified;
                    DB.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                string.Format("The return registry could't be saved because of \"{0}\" .", ex.Message);
                return(false);
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Here the rent of the boat is registred in the database
        /// </summary>
        /// <param name="personnumber"></param>
        /// <param name="boatid"></param>
        /// <returns></returns>
        public bool RentABoatRegistry(string personnumber, int boatid)
        {
            var rentopportunity = new Data.Booking();

            try
            {
                using (var DB = new Data.BoatBookingSystemEntities1())
                {
                    rentopportunity.PersonNumber    = personnumber;
                    rentopportunity.BoatID          = boatid;
                    rentopportunity.DeliveyDateTime = DateTime.Now;

                    DB.Bookings.Add(rentopportunity);
                    DB.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                string.Format("The rent registry could't be saved because of \"{0}\" .", ex.Message);
                return(false);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// This method returns the
        /// </summary>
        /// <param name="hours"></param>
        /// <param name="boatnumber"></param>
        /// <returns></returns>

        private decimal GetRentalPrice(int hours, int boatnumber)
        {
            List <Data.Category> _categorylist = new List <Data.Category>();

            using (var DB = new Data.BoatBookingSystemEntities1())
            {
                var bookingboat = DB.Bookings.Join(DB.Boats, booking =>
                                                   booking.BoatID,
                                                   boat => boat.BoatID,
                                                   (booking, boat) => new {
                    Booking                = booking,
                    Boat                   = boat,
                    CategoryID             = boat.CatID,
                    Category               = boat.Category.Name,
                    IsBiggerOrLike40foot   = boat.Category.OverSizeFourty,
                    PriceID                = boat.PriceID,
                    BasicFee               = boat.Price.BasicFee,
                    BasicSmallBoatMultiply = boat.Price.BasicPriceSmallBoatAlgorithm,
                    BasicBigBoatMultiply   = boat.Price.BasicPriceBigBoatAlgorithm,
                    HourFee                = boat.Price.HourFee,
                    HourSmallBoatMultiply  = boat.Price.HourPriceSmallBoatAlgorithm,
                    HourBigBoatMultiply    = boat.Price.HourPriceBigBoatAlgorithm
                })
                                  .Where(boat => boat.Boat.BoatID.Equals(boatnumber)).FirstOrDefault();

                multiplyBasicBigBoat   = (decimal)bookingboat.BasicBigBoatMultiply;
                multiplyBasicSmallBoat = (decimal)bookingboat.BasicSmallBoatMultiply;

                multiplyHourBigBoat   = (decimal)bookingboat.HourBigBoatMultiply;
                multiplyHourSmallBoat = (decimal)bookingboat.HourSmallBoatMultiply;

                //get the list of all category values
                _categorylist = GetValuesForCategoryName();

                if (bookingboat.Category.ToUpper() == "JOLLE" || bookingboat.Category.ToUpper() == "SEGELBÅT")
                {
                    categoryname = (CategoryName)Enum.Parse(typeof(CategoryName), bookingboat.Category.ToUpper().ToString());

                    switch (categoryname)
                    {
                    case Booking.CategoryName.SEGELBÅT:
                        if ((bool)bookingboat.IsBiggerOrLike40foot)
                        {
                            basicprice       = decimal.Multiply(bookingboat.BasicFee, multiplyBasicBigBoat);
                            hourpricebigboat = decimal.Multiply(bookingboat.HourFee, multiplyHourBigBoat);
                            hourprice        = decimal.Multiply(hourpricebigboat, hours);
                            totalprice       = decimal.Add(basicprice, hourprice);
                            break;
                        }
                        else
                        {
                            basicprice         = decimal.Multiply(bookingboat.BasicFee, multiplyBasicSmallBoat);
                            hourpricesmallboat = decimal.Multiply(bookingboat.HourFee, multiplyHourSmallBoat);
                            hourprice          = decimal.Multiply(hourpricesmallboat, hours);
                            totalprice         = decimal.Add(basicprice, hourprice);
                            break;
                        }

                    case Booking.CategoryName.JOLLE:
                        basicprice = bookingboat.BasicFee;
                        hourprice  = decimal.Multiply(bookingboat.HourFee, hours);
                        totalprice = decimal.Add(basicprice, hourprice);
                        break;

                    default:
                        basicprice = bookingboat.BasicFee;
                        hourprice  = decimal.Multiply(bookingboat.HourFee, hours);
                        totalprice = decimal.Add(basicprice, hourprice);
                        break;
                    }
                }
                else
                {
                    foreach (var item in _categorylist)
                    {
                        if (item.Name == bookingboat.Category)
                        {
                            if ((bool)bookingboat.IsBiggerOrLike40foot)
                            {
                                basicprice       = decimal.Multiply(bookingboat.BasicFee, multiplyBasicBigBoat);
                                hourpricebigboat = decimal.Multiply(bookingboat.HourFee, multiplyHourBigBoat);
                                hourprice        = decimal.Multiply(hourpricebigboat, hours);
                                totalprice       = decimal.Add(basicprice, hourprice);
                            }
                            else
                            {
                                basicprice         = decimal.Multiply(bookingboat.BasicFee, multiplyBasicSmallBoat);
                                hourpricesmallboat = decimal.Multiply(bookingboat.HourFee, multiplyHourSmallBoat);
                                hourprice          = decimal.Multiply(hourpricesmallboat, hours);
                                totalprice         = decimal.Add(basicprice, hourprice);
                            }
                        }
                    }
                }
            }
            return(Math.Round(totalprice, 2));
        }
Exemplo n.º 15
0
        private static void ChangeBoat()
        {
            var boat = new Data.Boat();
            int output = 0;
            var choice = "n";
            ShowBoats();
            Console.WriteLine();
            Console.Write(" Vill du ändra data på någon båt?, j/n: ");
            choice = Console.ReadLine();
            if (choice == "j")
            {
                Console.WriteLine();
                Console.WriteLine("**************** Ändra på data om båt **********************");
                Console.WriteLine();
                Console.WriteLine(" Vilken båt vill du ändra information om? ");
                Console.WriteLine(" Skriv det båt ID som ändringen gäller: ");
                Console.WriteLine();
                using (var DB = new Data.BoatBookingSystemEntities1())
                {

                    if (int.TryParse(Console.ReadLine(), out output))
                    {
                        var currentboat = DB.Boats.Where(x => x.BoatID == output).FirstOrDefault();
                        Console.Write(" Ändra namn på båten, j/n: ");
                        choice = Console.ReadLine();
                        if (choice == "j")
                        {
                            Console.WriteLine();
                            Console.Write(" Ändra namn: ");
                            var boatname = Console.ReadLine();
                            currentboat.Name = boatname;

                            Console.WriteLine();
                            Console.WriteLine(" Ändra kategori till båten, j/n: ");
                            choice = Console.ReadLine();
                            if (choice == "j")
                            {
                                GetCategories();
                                Console.WriteLine();
                                Console.WriteLine(" Ändra categori_id: ");
                                if (int.TryParse(Console.ReadLine(), out output))
                                    currentboat.CatID = output;

                                Console.WriteLine();
                                Console.WriteLine(" Ändra priskategori till båten, j/n: ");
                                choice = Console.ReadLine();
                                if (choice == "j")
                                {
                                    Console.WriteLine(" Ändra PrisID: ");
                                    if (int.TryParse(Console.ReadLine(), out output))
                                        currentboat.PriceID = output;
                                }

                            }
                            else
                            {
                                Console.WriteLine();
                                Console.WriteLine(" Ändra priskategori till båten, j/n: ");
                                choice = Console.ReadLine();
                                if (choice == "j")
                                {
                                    Console.WriteLine(" Ändra PrisID: ");
                                    if (int.TryParse(Console.ReadLine(), out output))
                                        currentboat.PriceID = output;
                                }

                            }
                        }
                        else
                        {

                            Console.WriteLine();
                            Console.Write(" Ändra kategori till båten, j/n: ");
                            choice = Console.ReadLine();
                            if (choice == "j")
                            {
                                GetCategories();
                                Console.WriteLine();
                                Console.Write(" Ändra categori_id: ");
                                if (int.TryParse(Console.ReadLine(), out output))
                                {
                                    currentboat.CatID = output;
                                }
                                else
                                {
                                    Console.WriteLine(" Felaktig inmatning categori_id:et har ingen referens ");
                                }
                                Console.WriteLine();
                                Console.WriteLine(" Ändra priskategori till båten, j/n: ");
                                choice = Console.ReadLine();
                                if (choice == "j")
                                {
                                    GetPrices();
                                    Console.WriteLine();
                                    Console.Write(" Ändra PrisID: ");
                                    if (int.TryParse(Console.ReadLine(), out output))
                                        currentboat.PriceID = output;
                                }
                            }
                            else
                            {
                                Console.WriteLine(" Ändra priskategori till båten, j/n: ");
                                choice = Console.ReadLine();
                                if (choice == "j")
                                {
                                    Console.WriteLine(" Ändra PrisID: ");
                                    if (int.TryParse(Console.ReadLine(), out output))
                                        currentboat.PriceID = output;
                                }
                                else
                                {
                                    Console.WriteLine();
                                    Console.WriteLine();
                                    Console.WriteLine(" Återgå till meny - tryck valfri tangent");
                                    Console.ReadKey();
                                    ShowMenu();
                                }
                            }
                        }
                    }
                    try
                    {
                        DB.SaveChanges();
                        ShowBoats();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("The boat could't be saved because of \"{0}\" .", ex.Message);
                    }
                }
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine(" Återgå till meny - tryck valfri tangent");
                Console.ReadKey();
                ShowMenu();

            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(" Återgå till meny - tryck valfri tangent");
            Console.ReadKey();
            ShowMenu();

        }
Exemplo n.º 16
0
        private static void CreateNewBoat()
        {
            var boat = new Data.Boat();
            int output = 0;

            Console.Clear();
            Console.WriteLine("================================");
            Console.WriteLine("Lägg till ny Båt");
            Console.WriteLine("================================");
            Console.WriteLine("Vilket namn skall båten ha? ");
            boat.Name = Console.ReadLine();

            using (var DB = new Data.BoatBookingSystemEntities1())
            {
                var categories = DB.Categories.ToList();

                foreach (var r in categories)
                {
                    Console.WriteLine("***************************************************************");
                    Console.WriteLine(" ID: " + r.CatID);
                    Console.WriteLine(" Namn: " + r.Name);

                    if (r.Name == "Segelbåt")
                    {
                        if (r.OverSizeFourty == true)
                        {
                            Console.WriteLine(" Över 40 tum.");
                        }
                        else
                        {
                            Console.WriteLine(" mindre än 40 tum.");
                        }
                    }
                    Console.WriteLine();
                }
            }
            GetCategories();
            Console.WriteLine("\r\nVälj Kategori_id: 1, 2, 3 osv.");

            using (var DB = new Data.BoatBookingSystemEntities1())
            {
                if (int.TryParse(Console.ReadLine(), out output))
                {
                    boat.CatID = output;
                }
                Console.WriteLine();
                GetPrices();
                Console.WriteLine("\r\nVälj Pris_id: 1, 2, 3 osv.");
                if (int.TryParse(Console.ReadLine(), out output))
                {
                    boat.PriceID = output;
                }
                try
                {
                    DB.Boats.Add(boat);
                    DB.SaveChanges();
                    ShowAllBoats();
                }
                catch (Exception ex)
                {
                    Console.Write("The boat could't be saved because of \"{0}\" .", ex.Message);
                }

            }
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine(" Återgå till meny - tryck valfri tangent");
            Console.ReadKey();
        }
Exemplo n.º 17
0
        private static void AddPrice()
        {
            var price = new Data.Price();
            decimal output = 0;
            bool exit = false;

            GetPrices();

            while (!exit)
            {
                Console.WriteLine(" Vill du lägga till en ny priskategori? j/n:");
                string choise = Console.ReadLine();
                if (choise == "n")
                {
                    Console.WriteLine(" Vill du ändra tidigare satta priser j/n:");
                    string changepricechoise = Console.ReadLine();
                    if (changepricechoise == "j")
                    {
                        ChangePrice();
                    }
                    else
                    {
                        ShowMenu();
                    }
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("================================");
                    Console.WriteLine(" Lägg till nytt pris");
                    Console.WriteLine("================================");
                    Console.WriteLine();
                    Console.WriteLine("Ange grundpris: ");

                    using (var DB = new Data.BoatBookingSystemEntities1())
                    {
                        try
                        {
                            if (decimal.TryParse(Console.ReadLine(), out output))
                            {
                                price.BasicFee = output;
                            }
                            Console.WriteLine();
                            Console.WriteLine("Ange timpris: ");
                            if (decimal.TryParse(Console.ReadLine(), out output))
                            {
                                price.HourFee = output;
                            }
                            Console.WriteLine("===============================================================");
                            Console.WriteLine(" Lägg till multipliceringssats för grundavgift.");
                            Console.WriteLine("===============================================================");
                            Console.WriteLine();
                            Console.WriteLine(" Ange multipliceringssats till grundavgiften för liten båt (ange , som decimalavskiljare): ");
                            Console.WriteLine();
                            if (decimal.TryParse(Console.ReadLine(), out output))
                            {
                                price.BasicPriceSmallBoatAlgorithm = output;
                            }
                            Console.WriteLine("  Ange multipliceringssats till grundavgiften för stor båt (ange , som decimalavskiljare): ");
                            Console.WriteLine();
                            if (decimal.TryParse(Console.ReadLine(), out output))
                            {
                                price.BasicPriceBigBoatAlgorithm = output;
                            }
                            Console.WriteLine("=================================================");
                            Console.WriteLine(" Lägg till multipliceringssats för timpris.");
                            Console.WriteLine("=================================================");
                            Console.WriteLine();
                            Console.WriteLine("Ange hur mycket timpriset för en liten båt skall multipliceras med: ");
                            Console.WriteLine();
                            if (decimal.TryParse(Console.ReadLine(), out output))
                            {
                                price.HourPriceSmallBoatAlgorithm = output;
                            }
                            Console.WriteLine("Ange hur mycket timpriset för en stor båt skall multipliceras med: ");
                            if (decimal.TryParse(Console.ReadLine(), out output))
                            {
                                price.HourPriceBigBoatAlgorithm = output;
                            }
                            DB.Prices.Add(price);
                            DB.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("The price could't be saved because of \"{0}\" .", ex.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
        private static void ChangePrice()
        {
            int output = 0;
            var choice = "n";

            using (var DB = new Data.BoatBookingSystemEntities1())
            {
                var prices = DB.Prices.ToList();
                Console.Clear();
                GetPrices();

                Console.WriteLine(" ================================");
                Console.WriteLine(" Ändra pris");
                Console.WriteLine(" ================================");
                Console.WriteLine();
                Console.Write(" Vilken priskategori vill du ändra välj PrisID: ");
                var pris_id = Console.ReadLine();
                if (int.TryParse(pris_id, out output))
                {
                    var newprice = DB.Prices.Where(x => x.PriceID == output).FirstOrDefault();
                    Console.WriteLine();
                    Console.Write(" Vill du andra grundavgift, j/n: ");
                    choice = Console.ReadLine();
                    {
                        if (choice == "j")
                        {
                            Console.WriteLine();
                            Console.Write(" Ändra grundavgift: ");
                            decimal bfoutput; ;
                            var basicfee = Console.ReadLine();

                            if (decimal.TryParse(basicfee, out bfoutput))
                            {
                                newprice.BasicFee = bfoutput;
                            }
                            Console.WriteLine();
                            Console.Write(" Ändra timavgift: ");
                            decimal hfoutput;
                            var hourfee = Console.ReadLine();
                            if (decimal.TryParse(hourfee, out hfoutput))
                            {
                                newprice.HourFee = hfoutput;
                            }
                            Console.WriteLine();
                            Console.Write(" Ändra grundavgift multipliceringssats liten båt (ange , som decimalavskiljare): ");
                            decimal bmsboutput;
                            var bmsb = Console.ReadLine();
                            if (decimal.TryParse(bmsb, out bmsboutput))
                            {
                                newprice.BasicPriceSmallBoatAlgorithm = bmsboutput;
                            }
                            Console.WriteLine();
                            Console.Write(" Ändra grundavgift multipliceringssats stor båt (ange , som decimalavskiljare): ");
                            decimal gmsboutput;
                            var gmsb = Console.ReadLine();
                            if (decimal.TryParse(gmsb, out gmsboutput))
                            {
                                newprice.BasicPriceBigBoatAlgorithm = gmsboutput;
                            }
                            Console.WriteLine();
                            Console.Write(" Ändra timprisets multipliceringssats liten båt (ange , som decimalavskiljare): ");
                            decimal hmsboutput = 0;
                            var hmsb = Console.ReadLine();
                            if (decimal.TryParse(hmsb, out hmsboutput))
                            {
                                newprice.HourPriceSmallBoatAlgorithm = hmsboutput;
                            }
                            Console.WriteLine();
                            Console.Write(" Ändra timprisets multipliceringssats stor båt (ange , som decimalavskiljare): ");
                            decimal hmlboutput = 0;
                            var hmlb = Console.ReadLine();

                            if (decimal.TryParse(hmlb, out hmlboutput))
                            {
                                newprice.HourPriceBigBoatAlgorithm = hmlboutput;
                            }
                        }
                        else
                        {
                            Console.WriteLine();
                            Console.Write(" Vill du andra timavgiften, j/n: ");
                            choice = Console.ReadLine();
                            if (choice == "j")
                            {
                                Console.WriteLine();
                                Console.Write(" Ändra timavgift: ");
                                decimal hfoutput;
                                var hourfee = Console.ReadLine();
                                if (decimal.TryParse(hourfee, out hfoutput))
                                {
                                    newprice.HourFee = hfoutput;
                                }
                                Console.WriteLine();
                                Console.Write(" Ändra grundavgift multipliceringssats liten båt (ange , som decimalavskiljare): ");
                                decimal bmsboutput;
                                var bmsb = Console.ReadLine();
                                if (decimal.TryParse(bmsb, out bmsboutput))
                                {
                                    newprice.BasicPriceSmallBoatAlgorithm = bmsboutput;
                                }
                                Console.WriteLine();
                                Console.Write(" Ändra grundavgift multipliceringssats stor båt (ange , som decimalavskiljare): ");
                                decimal gmsboutput;
                                var gmsb = Console.ReadLine();
                                if (decimal.TryParse(gmsb, out gmsboutput))
                                {
                                    newprice.BasicPriceBigBoatAlgorithm = gmsboutput;
                                }
                                Console.WriteLine();
                                Console.Write(" Ändra timprisets multipliceringssats liten båt (ange , som decimalavskiljare): ");
                                decimal hmsboutput = 0;
                                var hmsb = Console.ReadLine();
                                if (decimal.TryParse(hmsb, out hmsboutput))
                                {
                                    newprice.HourPriceSmallBoatAlgorithm = hmsboutput;
                                }
                                Console.WriteLine();
                                Console.Write(" Ändra timprisets multipliceringssats stor båt (ange , som decimalavskiljare): ");
                                decimal hmlboutput = 0;
                                var hmlb = Console.ReadLine();

                                if (decimal.TryParse(hmlb, out hmlboutput))
                                {
                                    newprice.HourPriceBigBoatAlgorithm = hmlboutput;
                                }
                            }
                            else
                            {
                                Console.WriteLine();
                                Console.Write(" Ändra grundavgift multipliceringssats liten båt (ange , som decimalavskiljare): ");
                                decimal bmsboutput;
                                var bmsb = Console.ReadLine();
                                if (decimal.TryParse(bmsb, out bmsboutput))
                                {
                                    newprice.BasicPriceSmallBoatAlgorithm = bmsboutput;
                                }
                                Console.WriteLine();
                                Console.Write(" Ändra grundavgift multipliceringssats stor båt (ange , som decimalavskiljare): ");
                                decimal gmsboutput;
                                var gmsb = Console.ReadLine();
                                if (decimal.TryParse(gmsb, out gmsboutput))
                                {
                                    newprice.BasicPriceBigBoatAlgorithm = gmsboutput;
                                }
                                Console.WriteLine();
                                Console.Write(" Ändra timprisets multipliceringssats liten båt (ange , som decimalavskiljare): ");
                                decimal hmsboutput = 0;
                                var hmsb = Console.ReadLine();
                                if (decimal.TryParse(hmsb, out hmsboutput))
                                {
                                    newprice.HourPriceSmallBoatAlgorithm = hmsboutput;
                                }
                                Console.WriteLine();
                                Console.Write(" Ändra timprisets multipliceringssats stor båt (ange , som decimalavskiljare): ");
                                decimal hmlboutput = 0;
                                var hmlb = Console.ReadLine();

                                if (decimal.TryParse(hmlb, out hmlboutput))
                                {
                                    newprice.HourPriceBigBoatAlgorithm = hmlboutput;
                                }
                            }
                        }
                        try
                        {
                            DB.SaveChanges();
                            var changedprices = DB.Prices.ToList();

                            GetPrices();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("The price could't be saved because of \"{0}\" .", ex.Message);
                        }

                    }
                }
                Console.WriteLine();
                Console.WriteLine();
                Console.WriteLine(" Återgå till meny - tryck valfri tangent");
                Console.ReadKey();
                ShowMenu();
            }
        }