public async Task Add(CreateServiceByAdminDto createService) { //Sprawdzić, czy parametry są poprawne //Usługa z DayWorkDto. Przenieść do helpera? var itemService = await _itemServiceRepository.Get(createService.ItemServiceId); var client = await _userRepository.GetUserById(createService.ClientId); var dayWork = await _dayWorkRepository.Get(createService.DayWorkId); if (itemService == null || client == null || dayWork == null) { throw new Exception("Bad Id"); } var serviceToDb = new Service(); serviceToDb.Id = Guid.NewGuid(); serviceToDb.ItemService = itemService; serviceToDb.Client = (UserClient)client; serviceToDb.DayWork = dayWork; serviceToDb.DateOfReservation = DateTime.Now; await _serviceRepsitory.AddService(serviceToDb); }
public async Task <IEnumerable <FreeServiceDto> > GetFreeServices(DateTime startDateTime, DateTime endDateTime, Guid itemId) { var serviceTime = (await _itemServiceRepository.Get(itemId)).DurationInMinutes; var dayWorks = (await _dayWorkRepository.Get(startDateTime.Date, endDateTime.Date)).ToList(); var offeredServices = await _itemServiceRepository.Get(); var minServiceTime = offeredServices.OrderBy(x => x.DurationInMinutes).FirstOrDefault().DurationInMinutes; var existedServices = new List <Service>(); var servicesToReturn = new List <FreeServiceDto>(); dayWorks.ForEach(dayWork => { for (DateTime currentTime = dayWork.StartDateTime; currentTime < dayWork.EndDateTime; currentTime = currentTime.AddMinutes(minServiceTime)) { existedServices.Clear(); existedServices = (List <Service>)(from service in dayWork.Services where service.StartTime > currentTime && service.StartTime <= currentTime.AddMinutes(serviceTime) select service); if (existedServices.Count == 0) { servicesToReturn.Add(new FreeServiceDto { StarTime = currentTime, EndTime = currentTime.AddMinutes(serviceTime), ServiceName = "TempServiceName", Provider = _mapper.Map <UserAdmin, ReturnAdminDto>(dayWork.ServiceProvider) }); } } }); return(servicesToReturn); }
public async Task Add(AddItemServiceDto itemService) { var tempItem = await _itemServiceRepository.Get(itemService.ServiceName); if (tempItem != null) { throw new Exception("Bad service name"); } var itemToDb = _mapper.Map <AddItemServiceDto, ItemService>(itemService); await _itemServiceRepository.AddItemSerivce(itemToDb); }