Exemplo n.º 1
0
        public async Task <IEnumerable <HoraryViewModel> > GetHoraryDrop(int type, int fieldItem, DateTime date, int horaryId)
        {
            List <HoraryViewModel> list = new List <HoraryViewModel>();
            var result = await _schedulingRepository.GetAll();


            if (type == 1)
            {
                int dayOfWeek = (int)date.DayOfWeek;

                var horary = await _horaryRepository.GetAll();

                foreach (var item in horary.Where(p => p.FieldItemId == fieldItem && p.DayWeek == dayOfWeek && p.State == true && p.Active == true))
                {
                    Scheduling scheduling = result.Where(p => p.Date == date && p.HoraryType == HoraryType.Default && p.HoraryId == item.Id).FirstOrDefault();

                    if (scheduling == null)
                    {
                        var newItem = new HoraryViewModel {
                            Hour = item.Hour, Id = item.Id
                        };
                        list.Add(newItem);
                    }
                    else
                    {
                        if (horaryId == scheduling.HoraryId)
                        {
                            var newItem = new HoraryViewModel {
                                Hour = item.Hour, Id = item.Id
                            };
                            list.Add(newItem);
                        }
                    }
                }
            }
            else
            {
                var horaryExtra = await _horaryExtraRepository.GetAll();

                foreach (var item in horaryExtra.Where(p => p.FieldItemId == fieldItem && p.Date == date))
                {
                    Scheduling scheduling = result.Where(p => p.Date == date && p.HoraryType == HoraryType.Extra && p.HoraryId == item.Id).FirstOrDefault();

                    if (scheduling == null)
                    {
                        var newItem = new HoraryViewModel {
                            Hour = item.Hour, Id = item.Id
                        };
                        list.Add(newItem);
                    }
                    else
                    {
                        if (horaryId == scheduling.HoraryId)
                        {
                            var newItem = new HoraryViewModel {
                                Hour = item.Hour, Id = item.Id
                            };
                            list.Add(newItem);
                        }
                    }
                }
            }

            return(list.OrderBy(p => p.Hour).Select(_mapper.Map <HoraryViewModel>));
        }
Exemplo n.º 2
0
 public async Task<IEnumerable<HoraryExtraViewModel>> GetAll()
 {
     var result = await _horaryExtraRepository.GetAll();
     return result.Select(_mapper.Map<HoraryExtraViewModel>);
 }