Example #1
0
        public Dictionary <DateTime, double> GetFutureNetWorthByMonth(DateTime currentDate, DateTime futureDate)
        {
            Dictionary <DateTime, double> netWorthDict = new Dictionary <DateTime, double>();
            List <DateTime> dates = DateCalculations.GetAllMonthsBetweenTwoDates(currentDate, futureDate);

            Asset[] assetsClone = new Asset[Assets.Count];
            Assets.CopyTo(assetsClone, 0);
            Liability[] liabilitiesClone = new Liability[Liabilities.Count];
            Liabilities.CopyTo(liabilitiesClone, 0);

            for (int i = 0; i < dates.Count; i++)
            {
                double futureNetWorth = 0;
                foreach (Asset a in assetsClone)
                {
                    futureNetWorth += (a.CurrentValue += Math.Abs(a.CurrentValue) * ((a.InterestRate / 12.0) / 100.0));
                }

                foreach (Liability l in liabilitiesClone)
                {
                    futureNetWorth -= (l.CurrentValue += Math.Abs(l.CurrentValue) * ((l.InterestRate / 12.0) / 100.0));
                }
                netWorthDict.Add(dates[i], futureNetWorth);
            }

            return(netWorthDict);
        }
        public void GetDifferenceInDaysTest_OneDaysDifference_returnsOne()
        {
            var startDate = new DateTime(DateTime.Now.Year, 2, 2);
            var endDate   = new DateTime(DateTime.Now.Year, 2, 3);

            Assert.IsTrue(DateCalculations.GetDifferenceInDays(startDate, endDate).Equals(1));
        }
        public ActionResult Index()
        {
            var userId = User.Identity.GetUserId();

            var periodEvents          = _unitOfWork.CycleEvents.GetPeriodEvents(userId);
            var twoLatestPeriodEvents = periodEvents.Take(2).ToList();
            var ovulationEvent        = _unitOfWork.CycleEvents.GetLatestOvulationEvent(userId);
            var futurePeriodDate      = DateTime.MinValue;

            if (ovulationEvent != null || periodEvents.Count >= 2)
            {
                futurePeriodDate = DateCalculations.GetFuturePeriodDate(ovulationEvent, periodEvents);
            }

            var averageCycleLength = periodEvents.Count < 2 ? 0 : DateCalculations.GetAverageCycleLength(periodEvents);

            var cycleModel = new CycleEvent()
            {
                StartDate = twoLatestPeriodEvents.Count <= 2 && twoLatestPeriodEvents.Count != 0 ? twoLatestPeriodEvents[0].StartDate : DateTime.MinValue,
                EndDate   = twoLatestPeriodEvents.Count <= 2 && twoLatestPeriodEvents.Count != 0 ? twoLatestPeriodEvents[0].EndDate : DateTime.MinValue,
                StartDateOfPreviousEvent = twoLatestPeriodEvents.Count == 2 ? twoLatestPeriodEvents[1].StartDate : DateTime.MinValue,
                OvulationDate            = ovulationEvent?.StartDate ?? DateTime.MinValue,
                FuturePeriodDate         = futurePeriodDate,
                AverageCycleLength       = averageCycleLength
            };

            return(View("Index", cycleModel));
        }
        public void GetWeekEndDateTest_SundaysDate_ReturnsSameSundaysDate()
        {
            var SundayDate   = new DateTime(2018, 11, 25);
            var ExpectedDate = new DateTime(2018, 11, 25);

            Assert.IsTrue(DateCalculations.GetWeekEndDate(SundayDate).ToShortDateString().Equals(ExpectedDate.ToShortDateString()));
        }
Example #5
0
        public ActionResult Create(CycleEventFormViewModel viewModel)
        {
            var userId = User.Identity.GetUserId();

            if (!ModelState.IsValid)
            {
                viewModel.Types = _unitOfWork.Types.GetEventTypes();
                return(View("CycleEventForm", viewModel));
            }

            var periodEvents = _unitOfWork.CycleEvents.GetPeriodEvents(userId);
            var days         = viewModel.Type == 1 ? DateCalculations.GetDaysToCalculate(periodEvents) : 0;

            var cycleEvent = new Event()
            {
                StartDate = viewModel.GetStartDate(),
                EndDate   = viewModel.GetEndDate(days),
                TypeId    = viewModel.Type,
                UserId    = userId
            };

            _unitOfWork.CycleEvents.Add(cycleEvent);
            _unitOfWork.Complete();

            return(RedirectToAction("GetRecentEvents", "CycleEvents"));
        }
        public void GetDifferenceInDaysTest_SameDates_returnZero()
        {
            var startDate = new DateTime(DateTime.Now.Year, 2, 2);
            var endDate   = new DateTime(DateTime.Now.Year, 2, 2);

            Assert.IsTrue(DateCalculations.GetDifferenceInDays(startDate, endDate).Equals(0));
        }
Example #7
0
        public ActionResult Update(CycleEventFormViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                viewModel.Types = _unitOfWork.Types.GetEventTypes();
                return(View("CycleEventForm", viewModel));
            }

            var userId     = User.Identity.GetUserId();
            var cycleEvent = _unitOfWork.CycleEvents.GetCycleEvent(viewModel.Id);

            if (cycleEvent == null)
            {
                return(HttpNotFound());
            }

            if (cycleEvent.UserId != userId)
            {
                return(new HttpUnauthorizedResult());
            }

            var periodEvents = _unitOfWork.CycleEvents.GetPeriodEvents(userId);
            var days         = viewModel.Type == 1 ? DateCalculations.GetDaysToCalculate(periodEvents) : 0;

            cycleEvent.Modify(viewModel.GetStartDate(), viewModel.GetEndDate(days), viewModel.Type);

            _unitOfWork.Complete();

            return(RedirectToAction("GetRecentEvents", "CycleEvents"));
        }
Example #8
0
        /// <summary>
        /// Return which service users are in a rota period
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public IEnumerable <ServiceUser> ServiceUsersInRotaPeriod(DateTime date)
        {
            DateTime rotaPeriodStart = DateCalculations.GetStartOfRotaPeriod(date);
            DateTime rotaPeriodEnd   = DateCalculations.GetEndOfRotaPeriod(date);

            return(ServiceUsers.Where(s => s.ServiceEnds > rotaPeriodStart && s.ServiceBegins < rotaPeriodEnd));
        }
Example #9
0
        public ActionResult List()
        {
            // Set the week start and end
            ViewBag.WeekStart = DateCalculations.GetWeekStartDate(DateTime.Now).ToShortDateString();
            ViewBag.WeekEnd   = DateCalculations.GetWeekEndDate(DateTime.Now).ToShortDateString();

            // Get the source list and map to the view model type.
            var list = _seminarService.GetSeminars();

            return(View(list));
        }
Example #10
0
        /// <summary>
        /// Checke whether this worker is off on this date
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public bool isDayOff(DateTime date)
        {
            if (date == DateTime.MinValue || _WorkingHours == null)
            {
                return(false);
            }

            int weekOfPeriod = DateCalculations.GetWeekIndexOfRotaPeriod(date);

            return(_WorkingHours.daysOff.Where(d => d.day == date.DayOfWeek && d.week == weekOfPeriod - 1).Count() > 0);
        }
Example #11
0
        /// <summary>
        /// Get how much call time that this person  has uncovered for a given weeek
        /// (for each call add up each calls duration)
        /// </summary>
        public double TotalCallTimeUnCovered_Mins_ForWeek(DateTime week)
        {
            DateTime startOfWeek = DateCalculations.GetStartOfWeek(week);

            double res = 0;

            foreach (Call call in Calls.Where(c => !c.HasFullWorkers && c.time >= startOfWeek && c.time <= startOfWeek.AddDays(7)))
            {
                res += call.duration_mins;
            }
            return(res);
        }
Example #12
0
        /// <summary>
        /// Get how much call time that this person is covering for a given weeek
        /// (for each call add up each calls duration)
        /// </summary>
        public int TotalCallTime_Mins_ForWeek(DateTime week)
        {
            DateTime startOfWeek = DateCalculations.GetStartOfWeek(week);

            int res = 0;

            foreach (Call call in Calls.Where(c => c.time >= startOfWeek && c.time <= startOfWeek.AddDays(7)))
            {
                res += call.duration_mins;
            }
            return(res);
        }
Example #13
0
        ///// <summary>
        ///// Get all the minutes of calls that are covered by the workers assigned hours
        ///// </summary>
        public int Assigned_Mins_ForWeek(DateTime week)
        {
            DateTime startOfWeek = DateCalculations.GetStartOfWeek(week);

            int assigned = 0;

            foreach (Call call in Calls.Where(c => c.time >= startOfWeek && c.time <= startOfWeek.AddDays(7)))
            {
                foreach (Availability avail in WorkingHours.Where(w => w.day == call.time.DayOfWeek))
                {
                    TimeSpan callTS    = new TimeSpan(call.time.Hour, call.time.Minute, 0);
                    TimeSpan callTSEnd = new TimeSpan(call.time.Hour, call.time.Minute + call.duration_mins, 0);

                    //if call finishes before this avaialbility
                    if (callTSEnd.CompareTo(avail.timeFrom) == -1)
                    {
                        continue;
                    }

                    //if the call starts after this availability length
                    if (callTS.CompareTo(avail.timeTo) == 1)
                    {
                        continue;
                    }


                    //otherwise lets find out how much of the call time is coveed by working hours
                    double mins_from_end   = avail.timeTo.TotalMinutes - callTSEnd.TotalMinutes;
                    double mins_from_start = callTS.TotalMinutes - avail.timeFrom.TotalMinutes;

                    if (mins_from_end < 0)
                    {
                        mins_from_end = 0;
                    }

                    if (mins_from_start < 0)
                    {
                        mins_from_start = 0;
                    }

                    double total = (avail.timeTo.TotalMinutes - avail.timeFrom.TotalMinutes) - (mins_from_end + mins_from_start);


                    //check how much of each call overlaps with each avail and add it here
                    assigned += (int)total;
                }
            }

            return(assigned);
        }
Example #14
0
        /// <summary>
        /// Refresh the dates in the period selection combo
        /// </summary>
        private void RefreshDateWeekCombo()
        {
            weekSelectionCombo.Items.Clear();

            DateTime currentPeriodStart = DateCalculations.GetStartOfRotaPeriod(DateTime.Now);

            Color pastCol = ColorTranslator.FromHtml("#FFA8A8");
            Color currCol = ColorTranslator.FromHtml("#72FE95");
            Color futrCol = ColorTranslator.FromHtml("#75ECFD");

            int range = Settings.Instance.rotarange;

            DateTime dateFrom = currentPeriodStart.AddDays(-(7 * Settings.Instance.rotaweekcount * range));
            DateTime dateTo   = dateFrom.AddDays((Settings.Instance.rotaweekcount * 7) - 1);

            for (int i = 0; i < (range * 2) + 1; i++)
            {
                Color col = currCol;

                if (i < range)
                {
                    col = pastCol;
                }
                else if (i > range)
                {
                    col = futrCol;
                }

                weekSelectionCombo.Items.Add(new ComboItem()
                {
                    obj = new RotaPeriod()
                    {
                        dateFrom = dateFrom, dateTo = dateTo
                    }, color = col
                });

                dateFrom = dateFrom.AddDays(7 * Settings.Instance.rotaweekcount);
                dateTo   = dateTo.AddDays(7 * Settings.Instance.rotaweekcount);
            }

            //select the current period as being start one
            weekSelectionCombo.SelectedIndex = range;

            //also select current week tab
            int weeksgone = (int)((DateTime.Now - currentPeriodStart).TotalDays / 7);

            KRBTabControl.TabPageEx tab = weekctrls[weeksgone].Parent as KRBTabControl.TabPageEx;
            tabcontrl.SelectedTab = tab;
        }
Example #15
0
        public double GetFutureNetWorth(DateTime currentDate, DateTime futureDate)
        {
            int    months         = DateCalculations.GetMonthsBetweenTwoDates(currentDate, futureDate);
            double futureNetWorth = 0;

            foreach (Asset a in Assets)
            {
                futureNetWorth += a.CurrentValue;
                if (a.HasInterest)
                {
                    futureNetWorth += Math.Abs(a.CurrentValue) * ((a.InterestRate / 12.0) / 100.0) * months;
                }
            }
            foreach (Liability l in Liabilities)
            {
                futureNetWorth -= l.CurrentValue;
                if (l.HasInterest)
                {
                    futureNetWorth -= Math.Abs(l.CurrentValue) * ((l.InterestRate / 12.0) / 100.0) * months;
                }
            }
            return(futureNetWorth);
        }
Example #16
0
        public void ShowListOfNumbers()
        {
            List <int> listOfNumbers = DateCalculations.GetListOfCalculatedNumbers(Start, Stop);

            PrintToConsole.ListOfCalculatedNumbersFromDates(Year, listOfNumbers);
        }