Exemple #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);
        }
Exemple #2
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);
        }