Ejemplo n.º 1
0
        //Gets Delivery dates for this productlist and time
        public List <DeliveryDate> GetDeliveryDates(string postalCode, Productlist product, int numberOfAllUpcomingDays)
        {
            List <DeliveryDate> deliveryDates     = new List <DeliveryDate>();
            List <DeliveryDate> tempDeliveryDates = new List <DeliveryDate>();

            for (int i = 0; i < numberOfAllUpcomingDays; i++) //(1 i +1)
            {
                DateTime upcomingDate = DateTime.Now.AddDays(i).Date.AddDays(product.DaysInAdvance);
                tempDeliveryDates.Add(new DeliveryDate(postalCode, upcomingDate));
            }
            //A delivery date is not valid if a product can't be delivered on that weekday
            foreach (var item in product.DeliveryDays)
            {
                deliveryDates.AddRange(tempDeliveryDates.Where(d => d.DDate.DayOfWeek == item));
            }
            return(deliveryDates);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the number of upcoming dates for the product
        /// </summary>
        /// <param name="product"></param>
        /// <param name="thisDayOfWeek"></param>
        /// <returns></returns>
        public int GetNumberOfAllUpcomingDays(Productlist product, int thisDayOfWeek)
        {
            int numberOfAllUpcomingDays;
            int daysInAdvance = product.DaysInAdvance;

            //All external products need to be ordered 5 days in advance
            if (product.Type == ProductType.External)
            {
                daysInAdvance = 5;
            }
            numberOfAllUpcomingDays = 14 - daysInAdvance;
            //Temporary products can only be ordered witin the current week
            if (product.Type == ProductType.Temporary)
            {
                numberOfAllUpcomingDays = 8 - daysInAdvance - thisDayOfWeek;
            }
            return(numberOfAllUpcomingDays);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Main Logic. The list of available Dates is calculated and returned.
        /// </summary>
        /// <param name="postalCode"></param>
        /// <param name="product"></param>
        /// <returns></returns>
        public List <DeliveryDate> ToDeliveryDateList(string postalCode, Productlist product)
        {
            //DateTime upcomingDate;
            int daysInAdvance = product.DaysInAdvance;

            //The number of the day of the week with Monday as 1 and Sunday as 7
            int thisDayOfWeek = GetThisDayOfWeekAsANumber();

            //Gets the number of upcoming dates for the product. Depends on how many days in advance the
            //product should be ordered and the product type
            int numberOfAllUpcomingDays = GetNumberOfAllUpcomingDays(product, thisDayOfWeek);

            //Gets Delivery dates for this productlist
            List <DeliveryDate> deliveryDates = GetDeliveryDates(postalCode, product, numberOfAllUpcomingDays);

            //Sorts deliver dates ascending.
            deliveryDates = deliveryDates.OrderBy(d => d.DDate).ToList();

            return(deliveryDates);
        }
Ejemplo n.º 4
0
        private void BtnStart_Click(object sender, EventArgs e)
        {
            string postalCode          = tbxPostalCode.Text;
            bool   postalCodeIsCorrect = CheckPostalCode(postalCode);

            if (!postalCodeIsCorrect)
            {
                return;
            }

            Productlist product = makeProduct();

            if (product != null)
            {
                Methods     methods     = new Methods();
                JsonMethods jsonMethods = new JsonMethods();

                OutputForm outForm = new OutputForm();
                outForm.Show();

                StringBuilder sb = new StringBuilder($"Id: {product.Id} Name: {product.Name} JSON: \n", 100);

                List <DeliveryDate> availableDates = methods.ToDeliveryDateList(postalCode, product);

                if (availableDates.Count > 0)
                {
                    sb.Append("{\n\"status\":success,\n \"data\":{\n deliveryDates");

                    sb.Append(jsonMethods.ToJson(availableDates) + "\n");
                    sb.Append("}\n}");
                    outForm.rtbxOutput.Text = sb.ToString();
                }
                else
                {
                    outForm.rtbxOutput.Text = "No avalible dates";
                }
                //}
            }
        }