private CalendarItemViewModel CheckAndCorrectCalendarItem(CalendarItemViewModel itemToCheck, DateTime from, DateTime to) { if (itemToCheck.from < from) { itemToCheck.from = from; } if (itemToCheck.to > to) { itemToCheck.to = to; } return(itemToCheck); }
public static int GetColumnIndexForCalendarItem(CalendarItemViewModel calendarItem, DateTime from, DateTime to) { int colIndex; colIndex = (calendarItem.from.Date - from.Date).Days; if (colIndex < 0 && calendarItem.to >= from.Date) { colIndex = 0; } if (colIndex > (to.Date - from.Date).Days) { colIndex = -1; } //colIndex lesser than 0 means wrong input data return(colIndex); }
public List <CalendarRowViewModel> GetCalendarRowData(List <Employee> empList, DateTime fromDate, DateTime toDate) { List <CalendarRowViewModel> calendarDataList = new List <CalendarRowViewModel>(); foreach (var emp in empList) { CalendarRowViewModel oneRow = new CalendarRowViewModel { id = emp.EmployeeID.ToString(), name = emp.LastName + " " + emp.FirstName, desc = " ", values = new List <CalendarItemViewModel>() }; foreach (var calendarItem in emp.CalendarItems) { if ((calendarItem.From <= fromDate && calendarItem.To >= fromDate) || (calendarItem.From >= fromDate && calendarItem.From <= toDate)) { CalendarItemViewModel oneItem = new CalendarItemViewModel(calendarItem); oneItem.desc += String.Format(" From: {0} - To: {1}", calendarItem.From.ToShortDateString(), calendarItem.To.ToShortDateString()); if (calendarItem.Type == CalendarItemType.SickAbsence) { Sickness selectedSick = (from s in repository.Sicknesses where ((s.From == calendarItem.From) && (s.To == calendarItem.To) && s.EmployeeID == calendarItem.EmployeeID) select s).FirstOrDefault(); if (selectedSick != null) { oneItem.sickType = selectedSick.SicknessType; } } CalendarItemViewModel correctedItem = CheckAndCorrectCalendarItem(oneItem, fromDate, toDate); correctedItem.from = correctedItem.from.ToUniversalTime(); correctedItem.to = correctedItem.to.ToUniversalTime(); oneRow.values.Add(correctedItem); } } calendarDataList.Add(oneRow); } List <CalendarRowViewModel> result = InsertFakeEmployee(calendarDataList, fromDate.ToUniversalTime(), toDate.ToUniversalTime()); return(result); //return calendarDataList; }
public void UpdateCalendarsItem_UpdateNotExistingEvent_ShouldThrowException(CalendarItemType type) { //Arrange var actualUpdatedEvent = new Event() { StartDateTime = new DateTime(2020, 4, 5), EndDateTime = new DateTime(2020, 4, 6) }; var actualItem = new CalendarItemViewModel() { MetaType = type }; var mockItemRepo = new Mock <ICalendarItemRepository>(); var mockEventRepo = new Mock <IEventRepository>(); var itemDomain = new CalendarItemDomain(mockItemRepo.Object, _mapper, null, mockEventRepo.Object); mockEventRepo.Setup(x => x.UpdateCalendarEvent(actualUpdatedEvent)).Verifiable(); // Act and Assert Assert.Throws <NotFoundException>(() => itemDomain.UpdateCalendarsItem(actualItem)); mockEventRepo.Verify(item => item.UpdateCalendarEvent(actualUpdatedEvent), Times.Never()); }
public static int GetColumnSpanForCalendarItem(CalendarItemViewModel calendarItem, DateTime from, DateTime to) { int colSpan = 0; int colIndex = GetColumnIndexForCalendarItem(calendarItem, from, to); if (colIndex < 0) { return(-1); } colSpan = (calendarItem.to.Date - calendarItem.from.Date).Days + 1; if (calendarItem.to.Date > to) { colSpan -= (calendarItem.to.Date - to.Date).Days; } if (calendarItem.from.Date < from) { colSpan -= (from.Date - calendarItem.from.Date).Days; } return(colSpan); }
public IActionResult PutCalendarsItems(CalendarItemViewModel calendarItem) { _itDomain.UpdateCalendarsItem(calendarItem); return(Ok()); }
public async Task <IActionResult> Index(int?id, int childId = 0) { _progId = childId; string userEmail = HttpContext.User.FindFirst("email")?.Value ?? _defaultUser; UserInfo userinfo = await _progenyHttpClient.GetUserInfo(userEmail); if (childId == 0 && userinfo.ViewChild > 0) { _progId = userinfo.ViewChild; } if (_progId == 0) { _progId = Constants.DefaultChildId; } Progeny progeny = await _progenyHttpClient.GetProgeny(_progId); List <UserAccess> accessList = await _progenyHttpClient.GetProgenyAccessList(_progId); int userAccessLevel = (int)AccessLevel.Public; if (accessList.Count != 0) { UserAccess userAccess = accessList.SingleOrDefault(u => u.UserId.ToUpper() == userEmail.ToUpper()); if (userAccess != null) { userAccessLevel = userAccess.AccessLevel; } } if (progeny.IsInAdminList(userEmail)) { _userIsProgenyAdmin = true; userAccessLevel = (int)AccessLevel.Private; } ApplicationUser currentUser = new ApplicationUser(); currentUser.TimeZone = userinfo.Timezone; var eventsList = await _progenyHttpClient.GetCalendarList(_progId, userAccessLevel); // _context.CalendarDb.AsNoTracking().Where(e => e.ProgenyId == _progId).ToList(); eventsList = eventsList.OrderBy(e => e.StartTime).ToList(); CalendarItemViewModel events = new CalendarItemViewModel(); events.IsAdmin = _userIsProgenyAdmin; events.UserData = currentUser; events.Progeny = progeny; events.EventsList = new List <CalendarItem>(); foreach (CalendarItem ev in eventsList) { if (ev.AccessLevel == (int)AccessLevel.Public || ev.AccessLevel >= userAccessLevel) { if (ev.StartTime.HasValue && ev.EndTime.HasValue) { ev.StartTime = TimeZoneInfo.ConvertTimeFromUtc(ev.StartTime.Value, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone)); if (ev.AllDay) { ev.EndTime = TimeZoneInfo.ConvertTimeFromUtc(ev.EndTime.Value + TimeSpan.FromDays(1), TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone)); } else { ev.EndTime = TimeZoneInfo.ConvertTimeFromUtc(ev.EndTime.Value, TimeZoneInfo.FindSystemTimeZoneById(userinfo.Timezone)); } // ToDo: Replace format string with configuration or userdefined value ev.StartString = ev.StartTime.Value.ToString("yyyy-MM-dd") + "T" + ev.StartTime.Value.ToString("HH:mm:ss"); ev.EndString = ev.EndTime.Value.ToString("yyyy-MM-dd") + "T" + ev.EndTime.Value.ToString("HH:mm:ss"); events.EventsList.Add(ev); } } } return(View(events)); }