Ejemplo n.º 1
0
        public async Task Add(CreateServiceByClientDto createService, Guid clientId)
        {
            //Sprawdzić, czy parametry są poprawne
            //Usługa z DayWorkDto. Przenieść do helpera?
            var client = await _userRepository.GetUserById(clientId);

            var itemService = await _itemServiceRepository.Get(createService.ItemServiceId);

            var dayWork = await _dayWorkRepository.Get(createService.DayWorkId);

            var temList = new List <DayWork>();

            temList.Add(dayWork);
            var currentServices = await _dayWorkService.GetFreeServices(createService.StartTime, createService.StartTime, createService.ItemServiceId);


            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);

            // var serviceProvider = await _userRepository.GetUserById(servicesData.ServiceProviderId);
            List <Service> services = new List <Service>();

            //servicesData.Dates.ForEach(date =>
            //{
            //    var startDate = date.AddHours(servicesData.StartHour)
            //                        .AddMinutes(servicesData.StartMinute);
            //    var endDate = date.AddHours(servicesData.EndHour)
            //                       .AddMinutes(servicesData.EndMinute);


            //    for(DateTime tempTime = startDate; tempTime<=endDate; tempTime = tempTime.AddMinutes(servicesData.RangeInMinutes))
            //    {
            //        services.Add(new Service
            //        {
            //            Id = Guid.NewGuid(),
            //        });
            //    }


            //});
            await _serviceRepsitory.AddListServices(services);
        }