public void CustomDisplayAbsenceDateForEMP_AbsenceDataNotNullReclaimDateNull_emptyString() { //Arrange var vc = new ViewContext(); vc.HttpContext = new FakeHttpContext(); HtmlHelper helper = new HtmlHelper(vc, new FakeViewDataContainer()); AbsenceFactorData data = new AbsenceFactorData { AbsenceFactorDataID = 1, From = new DateTime(2014, 01, 01), To = new DateTime(2014, 02, 02) }; string helperResult = String.Format("{0:dd'.'MM'.'yyyy}", data.From); //Act var result = helper.CustomDisplayAbsenceDateForEMP(data).ToString(); //Assert Assert.AreEqual(helperResult, result); }
public void CustomDisplayAbsenceDateForEMP_AbsenceDataNotNullReclaimDateNotNull_emptyString() { //Arrange var vc = new ViewContext(); vc.HttpContext = new FakeHttpContext(); HtmlHelper helper = new HtmlHelper(vc, new FakeViewDataContainer()); AbsenceFactorData data = new AbsenceFactorData { AbsenceFactorDataID = 1, From = new DateTime(2014, 01, 01), To = new DateTime(2014, 02, 02), ReclaimDate = new DateTime(2014, 03, 03) }; string statusHint = String.Format("{0:dd.MM.yyyy}", data.ReclaimDate); string helperResult = String.Format("<a <strike style=\"color:red\"><redText title=\"{0}\"> {1:dd'.'MM'.'yyyy} </redText></strike> </a>", statusHint, data.From); //Act var result = helper.CustomDisplayAbsenceDateForEMP(data).ToString(); //Assert Assert.AreEqual(helperResult, result); }
public static string CustomStatusHintForAbsenceData(AbsenceFactorData data) { return(String.Format("{0:dd.MM.yyyy}", data.ReclaimDate)); }
public static MvcHtmlString CustomDisplayAbsenceDateForEMP(this HtmlHelper helper, AbsenceFactorData absenceData) { if (absenceData != null) { if (absenceData.ReclaimDate != null) { string statusHint = CustomStatusHintForAbsenceData(absenceData); return(MvcHtmlString.Create(String.Format("<a <strike style=\"color:red\"><redText title=\"{0}\"> {1:dd'.'MM'.'yyyy} </redText></strike> </a>", statusHint, absenceData.From))); } return(MvcHtmlString.Create(String.Format("{0:dd'.'MM'.'yyyy}", absenceData.From))); } return(MvcHtmlString.Create("")); }
public PartialViewResult GetAbsenceDataPerEMP(string FromAbsence = "", string ToAbsence = "", string userName = "") { DateTime fromParsed = DateTime.Now; DateTime toParse = DateTime.Now; int FromYear = DateTime.Now.Year; int ToYear = DateTime.Now.Year; DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo; Calendar cal = dfi.Calendar; if (FromAbsence != "" && ToAbsence != "") { fromParsed = DateTime.ParseExact(FromAbsence, "dd.MM.yyyy", null); // check this toParse = DateTime.ParseExact(ToAbsence, "dd.MM.yyyy", null); // --------^ FromYear = fromParsed.Year; ToYear = toParse.Year; } else { return(PartialView("~/Views/WTR/GetWTRDataEmpty.cshtml")); } Employee employee = repository.Employees.Where(e => e.EID == userName).FirstOrDefault(); if (employee == null) { return(PartialView("NoData")); } AbsenceViewModelForEMP absenceData = new AbsenceViewModelForEMP { ID = employee.EID, FirstName = employee.FirstName, LastName = employee.LastName, FactorDetails = new Dictionary <CalendarItemType, List <AbsenceFactorData> >() }; List <AbsenceFactorData> sicknessList = new List <AbsenceFactorData>(); List <AbsenceFactorData> paidVacationList = new List <AbsenceFactorData>(); List <AbsenceFactorData> unpaidVacationList = new List <AbsenceFactorData>(); List <AbsenceFactorData> overtimeList = new List <AbsenceFactorData>(); List <AbsenceFactorData> paidOvertimeList = new List <AbsenceFactorData>(); List <AbsenceFactorData> privateOvertimeList = new List <AbsenceFactorData>(); List <AbsenceFactorData> journeyList = new List <AbsenceFactorData>(); if (employee.Sicknesses.Count != 0) { foreach (Sickness sick in employee.Sicknesses) { if (sick.From >= fromParsed && sick.To <= toParse) { AbsenceFactorData data = new AbsenceFactorData(); data.AbsenceFactorDataID = sick.SickID; data.From = sick.From; data.To = sick.To; sicknessList.Add(data); } } } if (employee.Vacations.Count != 0) { foreach (Vacation vacation in employee.Vacations.OrderBy(d => d.From)) { if (vacation.From >= fromParsed && vacation.To <= toParse) { switch (vacation.Type) { case VacationType.PaidVacation: AbsenceFactorData data = new AbsenceFactorData(); data.AbsenceFactorDataID = vacation.VacationID; data.From = vacation.From; data.To = vacation.To; paidVacationList.Add(data); break; case VacationType.UnpaidVacation: AbsenceFactorData dataUnpaid = new AbsenceFactorData(); dataUnpaid.AbsenceFactorDataID = vacation.VacationID; dataUnpaid.From = vacation.From; dataUnpaid.To = vacation.To; unpaidVacationList.Add(dataUnpaid); break; } } } } if (employee.Overtimes.Count != 0) { List <Overtime> overtimeDaysOffTrue = employee.Overtimes.Where(d => d.DayOff == true).OrderBy(d => d.Date).ToList(); foreach (Overtime overtime in overtimeDaysOffTrue) { if (overtime.Date >= fromParsed && overtime.Date <= toParse) { switch (overtime.Type) { //case OvertimeType.Overtime: // AbsenceFactorData overtimeData = new AbsenceFactorData(); // overtimeData.AbsenceFactorDataID = overtime.OvertimeID; // overtimeData.From = overtime.Date; // overtimeData.To = overtime.Date; // overtimeData.ReclaimDate = overtime.ReclaimDate; // overtimeList.Add(overtimeData); // break; case OvertimeType.Paid: AbsenceFactorData paidOvertime = new AbsenceFactorData(); paidOvertime.AbsenceFactorDataID = overtime.OvertimeID; paidOvertime.From = overtime.Date; paidOvertime.To = overtime.Date; paidOvertime.ReclaimDate = overtime.ReclaimDate; paidOvertimeList.Add(paidOvertime); if (overtime.ReclaimDate != null && overtime.ReclaimDate != DateTime.MinValue) { AbsenceFactorData overtimeData = new AbsenceFactorData(); overtimeData.AbsenceFactorDataID = overtime.OvertimeID; overtimeData.From = overtime.ReclaimDate.Value; overtimeData.To = overtime.ReclaimDate.Value; overtimeData.ReclaimDate = overtime.Date; overtimeList.Add(overtimeData); } break; case OvertimeType.Private: AbsenceFactorData privateOvertime = new AbsenceFactorData(); privateOvertime.AbsenceFactorDataID = overtime.OvertimeID; privateOvertime.From = overtime.Date; privateOvertime.To = overtime.Date; privateOvertime.ReclaimDate = overtime.ReclaimDate; privateOvertimeList.Add(privateOvertime); break; } } } } if (employee.BusinessTrips.Count != 0) { List <Journey> employeeJourneys = (from bts in repository.BusinessTrips where bts.EmployeeID == employee.EmployeeID from j in bts.Journeys where j.BusinessTripID == bts.BusinessTripID && j.DayOff == true orderby j.Date select j).ToList(); if (employeeJourneys.Count != 0) { foreach (Journey journey in employeeJourneys) { if (journey.Date >= fromParsed && journey.Date <= toParse) { AbsenceFactorData journeyData = new AbsenceFactorData(); journeyData.AbsenceFactorDataID = journey.JourneyID; journeyData.From = journey.Date; journeyData.To = journey.Date; journeyData.ReclaimDate = journey.ReclaimDate; journeyList.Add(journeyData); if (journey.ReclaimDate != null && journey.ReclaimDate != DateTime.MinValue && journey.DayOff == true) { AbsenceFactorData overtimeData = new AbsenceFactorData(); overtimeData.AbsenceFactorDataID = journey.JourneyID; overtimeData.From = journey.ReclaimDate.Value; overtimeData.To = journey.ReclaimDate.Value; overtimeData.ReclaimDate = journey.Date; overtimeList.Add(overtimeData); } } } } } absenceData.FactorDetails.Add(CalendarItemType.SickAbsence, sicknessList); absenceData.FactorDetails.Add(CalendarItemType.PaidVacation, paidVacationList); absenceData.FactorDetails.Add(CalendarItemType.UnpaidVacation, unpaidVacationList); absenceData.FactorDetails.Add(CalendarItemType.ReclaimedOvertime, overtimeList); absenceData.FactorDetails.Add(CalendarItemType.OvertimeForReclaim, paidOvertimeList); absenceData.FactorDetails.Add(CalendarItemType.PrivateMinus, privateOvertimeList); absenceData.FactorDetails.Add(CalendarItemType.Journey, journeyList); if (sicknessList.Count == 0 && paidVacationList.Count == 0 && unpaidVacationList.Count == 0 && overtimeList.Count == 0 && paidVacationList.Count == 0 && privateOvertimeList.Capacity == 0 & journeyList.Count == 0) { return(PartialView("NoAbsenceData")); } ViewBag.FromWeek = cal.GetWeekOfYear(fromParsed, dfi.CalendarWeekRule, dfi.FirstDayOfWeek); ViewBag.ToWeek = cal.GetWeekOfYear(toParse, dfi.CalendarWeekRule, dfi.FirstDayOfWeek); ViewBag.FromYear = FromYear; ViewBag.ToYear = ToYear; return(PartialView("GetAbsenceDataPerEMP", absenceData)); }