예제 #1
0
        public static BillingCost GetPriceEstimateRental
            (string email,
            InventoryGroup[] desiredBikes,
            DateSelection dateSelections)
        {
            double taxPercentage = Convert.ToDouble(GetParameterValue("taxPercentage"));

            BillingCost billingCost = new BillingCost();

            BikePrices[] bikeprices = DatabaseOperations.GetPrices();

            if (dateSelections != null && dateSelections.Date != null)
            {
                bool isWeekend = dateSelections.DateDayOfTheWeek == DayOfWeek.Saturday ||
                                 dateSelections.DateDayOfTheWeek == DayOfWeek.Sunday;

                foreach (InventoryGroup desiredBike in desiredBikes
                         .Where(desiredBike => desiredBike.Wanted > 0))
                {
                    BikePrices[] bikePricesValues
                        = bikeprices.Where(bike => bike.BikeId == desiredBike.BikeId).ToArray();

                    if (bikePricesValues.Count() != 1)
                    {
                        throw new System.Exception("Unable to get bikeprice");
                    }
                    BikePrices bikePrices = bikePricesValues.Single();

                    if (isWeekend == false)
                    {
                        billingCost.Price += desiredBike.Wanted * Convert.ToDouble(bikePrices.Evening.Replace("$", ""));
                    }
                    else if (dateSelections.DayPartEnum == DayPartSelection.DayPart.Day)
                    {
                        billingCost.Price += desiredBike.Wanted * Convert.ToDouble(bikePrices.DayWeekend.Replace("$", ""));
                    }
                    else if (dateSelections.DayPartEnum == DayPartSelection.DayPart.Evening)
                    {
                        billingCost.Price += desiredBike.Wanted * Convert.ToDouble(bikePrices.Evening.Replace("$", ""));
                    }
                    else
                    {
                        billingCost.Price += desiredBike.Wanted * Convert.ToDouble(bikePrices.HalfDayWeekend.Replace("$", ""));
                    }
                }
            }
            billingCost.Price = Math.Round(billingCost.Price, 2);
            billingCost.Tax   = Math.Round(taxPercentage * billingCost.Price, 2);

            billingCost.Discount = GetDiscount(email);

            return(billingCost);
        }
예제 #2
0
        public static string InsertAppointment(DateSelection dateSelectionInstance,
                                               string name, string email, string phone)
        {
            using (var conn = new SqlConnection(ConnectionString))
            {
                string id = Guid.NewGuid().ToString();

                string date = $"{dateSelectionInstance.CSharpDayTime.Month}/{dateSelectionInstance.CSharpDayTime.Day}/{dateSelectionInstance.CSharpDayTime.Year}";

                string sqlString = $"insert into [dbo].[APPOINTMENTS] (id,date, name, email, phone, daypart) values('{id}', '{date}','{name}', '{email}', '{phone}', '{dateSelectionInstance.DayPartEnum.ToString()}')";

                using (var command = new SqlCommand(sqlString, conn))
                {
                    conn.Open();

                    command.ExecuteNonQuery();
                }
                return(id);
            }
        }
예제 #3
0
        public BikesAvailability(
            DateSelection dateSelection,
            string name,
            string email,
            string phone)
        {
            DateSelection = dateSelection;

            if (name != null)
            {
                Name = name.ToString();
            }
            if (email != null)
            {
                Email = email.ToString();
            }
            if (phone != null)
            {
                Phone = phone.ToString();
            }
        }
예제 #4
0
        GetBikesAvailability(InventoryGroup[] inventoryGroups,
                             string name,
                             string email,
                             string phone,
                             DateTime startDate,
                             DateTime endDate,
                             DateSelection dateSelection)
        {
            BikesAvailability bikesAvailability
                = new BikesAvailability(
                      dateSelection,
                      name,
                      email,
                      phone);


            List <DisplayTime> availableDates = new List <DisplayTime>();

            DateTime runningDate = new DateTime(startDate.Ticks);

            DateTime toDate = new DateTime(endDate.Ticks);

            bikesAvailability.Inventory = inventoryGroups?.ToArray() ?? GetInventory();

            Appointment[] appointments = DatabaseOperations.GetAppointments();

            while (runningDate <= toDate)
            {
                List <DayPartSelection.DayPart> availableDayParts =
                    new List <DayPartSelection.DayPart>(DayPartSelection.GetAvailableDayParts(runningDate));

                foreach (DayPartSelection.DayPart dayPart in DayPartSelection.AllDayParts)
                {
                    Appointment[] appointmentsTodayAndDayPart =
                        appointments.Where(appointment => appointment.Date.Ticks == runningDate.Ticks &&
                                           appointment.DayPartOverlaps(dayPart))
                        .ToArray();

                    BikeBooking[] bikeBookings
                        = appointmentsTodayAndDayPart.SelectMany(a => a.BikeBookings)
                          .ToArray();

                    InventoryGroup[] newInventoryGroups = bikesAvailability.Inventory.Select(i => new InventoryGroup(i)).ToArray();

                    foreach (InventoryGroup inventoryGroup in newInventoryGroups)
                    {
                        BikeBooking[] overlappingBikeBookings =
                            bikeBookings.Where(b => b.BikeId == inventoryGroup.BikeId &&
                                               b.ModelId == inventoryGroup.ModelId).ToArray();

                        foreach (BikeBooking overlappingBikeBooking in overlappingBikeBookings)
                        {
                            inventoryGroup.Available--;

                            if (inventoryGroup.Wanted > inventoryGroup.Available)
                            {
                                availableDayParts.Remove(dayPart);
                            }
                        }
                    }
                }
                availableDates.Add(new DisplayTime(runningDate, availableDayParts.ToArray()));

                runningDate = runningDate.AddDays(1);
            }

            bikesAvailability.AvailableDates = availableDates.ToArray();

            if (availableDates.Any() == false)
            {
                bikesAvailability.Message = $"The bikes you want are not available in the timeframe you specified";
            }

            Event[] plannedEvents = GetEvents();

            bikesAvailability.BillingCost = new BillingCost();

            if (!(dateSelection == null || plannedEvents.Any(e => e.Date.Ticks == dateSelection.CSharpDayTime.Ticks)))
            {
                bikesAvailability.BillingCost
                    = GetPriceEstimateRental(email, bikesAvailability.Inventory, dateSelection);
            }

            return(bikesAvailability);
        }
예제 #5
0
        public static string MakeReservation(InventoryGroup[] inventoryGroups,
                                             string name,
                                             string email,
                                             string phoneNumber,
                                             DateSelection dateSelection)
        {
            string message = "An unexpected error occured";

            if (string.IsNullOrEmpty(name.Trim()))
            {
                message = "Please enter your name";
                return(message);
            }
            else if (string.IsNullOrEmpty(email.Trim()))
            {
                message = "Please enter your email";
                return(message);
            }
            else if (email.Trim().Count(c => c == '.') != 1 ||
                     email.Trim().Count(c => c == '@') != 1)
            {
                message = "Please enter a valid email address";
                return(message);
            }
            else if (string.IsNullOrEmpty(phoneNumber.Trim()))
            {
                message = "Please enter your phone number";
                return(message);
            }
            else if (phoneNumber.Count(x => Char.IsDigit(x)) != 10 &&
                     phoneNumber.Count(x => Char.IsDigit(x)) != 7)
            {
                message = "Please enter a valid phone number. The form excepts 7 (Fort Collins number) or 10 digits";
                return(message);
            }
            else if (dateSelection == null)
            {
                message = "Please select at least one date";
                return(message);
            }
            else if (inventoryGroups.All(g => g.Wanted == 0))
            {
                message = "Please select some bikes";
                return(message);
            }
            string id = string.Empty;

            BillingCost billingCost = GetPriceEstimateRental(email, inventoryGroups, dateSelection);

            id = DatabaseOperations.InsertAppointment
                     (dateSelection, name.ToString(), email.ToString(), phoneNumber.ToString());



            DatabaseOperations.AddBikeBookings(id, inventoryGroups);

            message = "Booking was successful";

            List <string> messageLines = new List <string>();

            messageLines.Add($"Id: '{id}'");
            messageLines.Add($"name: {name}");
            messageLines.Add($"email: {email}");
            messageLines.Add($"phone: {phoneNumber}");
            messageLines.Add($"price (incl tax): {billingCost.Price+ billingCost.Tax}");
            messageLines.Add($"{dateSelection.Date} {dateSelection.DayPart}");

            messageLines.Add($"Bikes:");
            foreach (InventoryGroup inventoryGroup in inventoryGroups)
            {
                if (inventoryGroup.Wanted > 0)
                {
                    messageLines.Add($"{inventoryGroup.Name}: {inventoryGroup.Model}");
                }
            }

            string renderedFullMessage = messageLines.Aggregate((i, j) => i + "\n" + j);

            string companyEmail = GetCompanyEmailAddress();

            string msg1 = new EmailSender(companyEmail).SendToBikeadelics($"Reservation", renderedFullMessage);

            if (msg1 == EmailSender.MessageAtSuccessfullySentEmail)
            {
                message += $" Email successfully sent to bikeadelic";
            }
            else
            {
                message += $" Unable to sent email to bikeadelic";
            }

            if (string.IsNullOrEmpty(email.ToString()) == false)
            {
                string rentedBikesMessagePart =
                    inventoryGroups.Where(g => g.Wanted > 0)
                    .Select((kvpi, kvpj) => $"{ kvpi.Wanted}  { kvpi.Name}")
                    .Aggregate((i, j) => $"{i} and {j}");

                string daySelectionPartMessage = $"{dateSelection.Date}";

                string GetDropOffTimeByDayPart(string dayPart)
                {
                    return(new Dictionary <string, string>
                    {
                        { DayPartSelection.DayPart.Morning.ToString(), "9.00AM" },
                        { DayPartSelection.DayPart.Afternoon.ToString(), "2.00PM" },
                        { DayPartSelection.DayPart.Day.ToString(), "9.00AM" },
                        { DayPartSelection.DayPart.Evening.ToString(), "4.00PM" }
                    }[dayPart]);
                }

                string dropOffTimePartMessage = dateSelection.DayPart != null?
                                                $" at {GetDropOffTimeByDayPart(dateSelection.DayPart)}":
                                                string.Empty;

                string customerMessage = $"Dear {name} \n\n" +
                                         $"Thank you for your reservation of {rentedBikesMessagePart}. \n\n" +
                                         $"We have you down for {daySelectionPartMessage}. \n\n" +
                                         $"We are looking forward to see you {dropOffTimePartMessage}. \n\n" +
                                         $"Please have cash payment of ${billingCost.Price} + tax ${billingCost.Tax} = ${billingCost.Price + billingCost.Tax} ready when you meet us there \n\n" +
                                         $"We will contact you at {email} or {phoneNumber} to confirm.\n\n" +
                                         $"Thank you for your business and looking forward to meet you.\n\n" +
                                         $"Arjan de Bruijn and Allison Shaw";

                string msg2 = EmailSender.Send(email.ToString(), $"Your reservation", customerMessage);

                if (msg2 == EmailSender.MessageAtSuccessfullySentEmail)
                {
                    message += $" Email successfully sent to {email.ToString()}";
                }
                else
                {
                    message += $" Unable to sent email to {email.ToString()}";
                }
            }
            else
            {
                message += " no email sent to customer, no address provided";
            }
            return(message);
        }