public async Task <IHttpActionResult> Calendar(WorkScheduleFilterViewModel filter)
 {
     return(Ok(await WebApiService.Instance.PostAsync <WorkScheduleResultViewModel>("calendar/list", filter)));
 }
        public WorkScheduleResultViewModel GetWorkScheduleByDate(WorkScheduleFilterViewModel filter)
        {
            var today           = GeneralService.CurrentDate;
            var isPlanSubmitted = false;
            var startDate       = new DateTime(filter.Year == 0 ? today.Year : filter.Year, filter.Month == 0 ? today.Month : filter.Month, 1);
            var lastDate        = startDate.AddMonths(1).AddDays(-1);
            var fixedDay        = GetDayOffMonth(filter.UserId, startDate, lastDate);

            var newInstance     = new GenericUnitOfWork();
            var getWorkSchedule = newInstance.GetRepository <WorkSchedule, Guid>();

            var dateWiseWorkSchedules = fixedDay.GroupJoin(getWorkSchedule.GetAll(), i => i, p => p.Date, (i, g) => new { i = i, g = g }).Where(g => !g.g.Any()).ToList();

            dateWiseWorkSchedules.ForEach(c =>
            {
                getWorkSchedule.Add(new WorkSchedule()
                {
                    UserId           = filter.UserId,
                    Date             = c.i,
                    OffDay           = true,
                    Description      = "Day OFF",
                    WorkScheduleType = WorkScheduleType.Others,
                    PostedById       = new Guid(ApplicationConstants.SuperAdminUserId),
                    CreatedDate      = GeneralService.CurrentDate
                });
            });
            if (dateWiseWorkSchedules.Any())
            {
                newInstance.SaveChanges();
            }



            var workSchedules = _genericUnitOfWork.GetRepository <WorkSchedule, Guid>().GetAll()
                                .Where(c => c.Date >= startDate && c.Date <= lastDate && c.UserId == filter.UserId && (c.WorkScheduleType == WorkScheduleType.Others || c.WorkScheduleType == WorkScheduleType.CrossAssignmnt)).ToList();



            var startDay = new DateTime(today.Year, today.Month, 01);

            if (startDay > startDate)
            {
                isPlanSubmitted = true;
            }
            else
            {
                isPlanSubmitted =
                    _genericUnitOfWork.GetRepository <WorkScheduleSubmission, Guid>()
                    .GetAll()
                    .SingleOrDefault(
                        c =>
                        c.MonthOfSubmission >= startDate && c.MonthOfSubmission <= lastDate &&
                        c.AreaAdministratorId == filter.UserId) != null;
            }

            var mapped = _mapper.Map <IList <WorkSchedule>, IList <WorkScheduleViewModel> >(workSchedules.ToList()) ?? new List <WorkScheduleViewModel>();

            var meetingSchedules = _genericUnitOfWork.GetRepository <MeetingSchedule, Guid>().GetAll().Where(c => c.Date >= startDate && c.Date <= lastDate).ToList();

            meetingSchedules.ForEach(c =>
            {
                mapped.Add(new WorkScheduleViewModel()
                {
                    Id                = c.Id,
                    Description       = c.Description,
                    Date              = c.Date.ToShortDateString(),
                    Title             = c.Title,
                    IsMeetingSchedule = true,
                    SchedualeDate     = c.Date
                });
            });


            IList <DateViewModel> explodeDates = new List <DateViewModel>();
            var newDate = new DateTime(startDate.Year, startDate.Month, startDate.Day);

            var k = 1;

            while (newDate <= lastDate)
            {
                explodeDates.Add(new DateViewModel()
                {
                    SchedualeDate = newDate,
                    IsDummy       = false,
                    IsPastDate    = newDate <= DateTime.Today.Date,
                    Day           = (int)startDate.DayOfWeek,
                    Number        = k++
                });
                newDate = newDate.AddDays(1);
            }

            var records = explodeDates.GroupJoin(mapped, d => d.SchedualeDate, s => s.SchedualeDate, (d, s) => new WorkScheduleDayViewModel
            {
                Date       = d.SchedualeDate.ToShortDateString(),
                IsDummy    = d.IsDummy,
                IsPastDate = d.IsPastDate,
                Day        = d.Day,
                Number     = d.Number,
                Events     = s.ToList()
            }).ToList();



            return(new WorkScheduleResultViewModel()
            {
                IsPlanSubmitted = isPlanSubmitted,
                Month = lastDate.Month,
                Year = lastDate.Year,
                WorkScheduleDays = records,
                Caption = lastDate.ToString("MMMM", CultureInfo.CreateSpecificCulture("en-US")) + " " + lastDate.Year,
                TotalDays = System.DateTime.DaysInMonth(lastDate.Year, lastDate.Month)
            });
        }
        public IHttpActionResult GetListByDate(WorkScheduleFilterViewModel model)
        {
            var response = CalendarService.GetWorkScheduleByDate(model);

            return(Ok(response));
        }
Beispiel #4
0
 public async Task <IHttpActionResult> Calendar(WorkScheduleFilterViewModel filter)
 {
     return(Ok(await WebApiService.Instance.PostAsync <WorkScheduleResultViewModel>("branchoperation/workschedule/datewise", filter)));
 }