예제 #1
0
        public ActionResult reisGezelschap(string titel, int kinderen2, string kamers2, string datum2)
        {
            Accommodatie accommodatie = accommodatieRepository.GetAccommodatie(titel);
            DateTime     datum        = Convert.ToDateTime(datum2);
            int          kinderen     = Convert.ToInt32(kinderen2);
            int          kamers       = Convert.ToInt32(kamers2);

            return(Json(new { price = PrijsBerekening(accommodatie, datum, kinderen, kamers) }));
        }
        public Accommodatie GetAccommodatie(string title)
        {
            //todo: query verkleinen
            string       query        = "Select * from Accommodatie where titel = '" + title + "'";
            DataTable    data         = new DataTable();
            Accommodatie accommodatie = new Accommodatie();
            SqlCommand   cmnd         = new SqlCommand(query, this.Conn);

            using (SqlConnection connection = new SqlConnection(Database.connectionString))
                using (SqlCommand command = new SqlCommand(query, connection))
                {
                    connection.Open();
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            accommodatie.ID              = (int)reader[0];
                            accommodatie.Title           = (string)reader[1];
                            accommodatie.Description     = (string)reader[2];
                            accommodatie.Country         = (string)reader[3];
                            accommodatie.Volwasseneprijs = (decimal)reader[5];
                            accommodatie.Kinderprijs     = (decimal)reader[6];
                        }
                    }
                }
            data.Dispose();
            query = "Select aa.Link from Accommodatie ac left join AccommodatieAfbeeldingen aa on ac.ID=aa.Accommodatie_ID where ac.Titel=@Titel";
            cmnd  = new SqlCommand(query, this.Conn);
            cmnd.Parameters.AddWithValue("@Titel", title);
            data = this.Select(cmnd);

            if (data.Rows.Count > 0)
            {
                foreach (DataRow picture in data.Rows)
                {
                    accommodatie.Picture.Add(Convert.ToString((picture["Link"])));
                }
            }
            data.Dispose();
            query = "Select v.Datum from Accommodatie ac join Accommodatie_VertrekDatum av on ac.ID = av.Accommodatie_ID join VertrekDatum v on av.VertrekDatum_ID = v.ID where ac.Titel= @Titel";
            cmnd  = new SqlCommand(query, this.Conn);
            cmnd.Parameters.AddWithValue("@Titel", title);
            data = this.Select(cmnd);

            if (data.Rows.Count > 0)
            {
                foreach (DataRow datum in data.Rows)
                {
                    accommodatie.DepartureDate.Add(Convert.ToDateTime(datum["Datum"]));
                }
            }
            return(accommodatie);
        }
예제 #3
0
        public decimal PrijsBerekening(Accommodatie accommodatie, DateTime datum, int kinderen, int kamers)
        {
            AccommodatieViewModel accommodatieViewModel = new AccommodatieViewModel()
            {
                Accommodatie   = accommodatie,
                Datum          = datum,
                AantalKinderen = kinderen,
                AantalKamers   = kamers
            };

            Session["Reisdata"] = accommodatieViewModel;

            decimal ChildrenPrice;
            decimal AdultPrice;
            int     toeslag = 0;

            int[] months = new int[12];
            months[0]  = 120;
            months[1]  = 110;
            months[2]  = 100;
            months[3]  = 110;
            months[4]  = 120;
            months[5]  = 130;
            months[6]  = 120;
            months[7]  = 110;
            months[8]  = 100;
            months[9]  = 110;
            months[10] = 120;
            months[11] = 130;

            System.Globalization.DateTimeFormatInfo mfi = new System.Globalization.DateTimeFormatInfo();
            string monthname = mfi.GetMonthName(datum.Month).ToString();
            Month  month     = (Month)Enum.Parse(typeof(Month), monthname);

            AdultPrice    = (accommodatie.Volwasseneprijs * 2) * months[(int)month] / 100;
            ChildrenPrice = (accommodatie.Kinderprijs * kinderen) * months[(int)month] / 100;
            if (kamers == 3)
            {
                toeslag = 50;
            }
            return(AdultPrice + ChildrenPrice + toeslag + 20.50m);
        }