public ResponseModel GetWorkHoursMock(DateTime date, Employee employee, Domain.Entities.Services service) { var response = new ResponseModel(); try { List <DateTime> intervals = new List <DateTime>(); // Horário comercial, 09:00 - 18:00 var workHours = new EmployeeWorkHours { EmployeeWorkHoursId = Guid.NewGuid(), StartHour = new DateTime(date.Year, date.Month, date.Day, 09, 00, 00), EndHour = new DateTime(date.Year, date.Month, date.Day, 18, 00, 00), StartInterval = new DateTime(date.Year, date.Month, date.Day, 12, 00, 00), EndInterval = new DateTime(date.Year, date.Month, date.Day, 13, 00, 00) }; var schedulings = _schedulingRepository.GetDaySchedulingsByEmployee(employee.EmployeeId, date); DateTime StartTime = workHours.StartHour; DateTime EndTime = workHours.EndHour; while (StartTime <= EndTime.AddMinutes(service.DurationMinutes * -1)) { StartTime = StartTime.AddMinutes(service.DurationMinutes); intervals.Add(StartTime); } List <DateTime> exclude = new List <DateTime>(); intervals.ForEach(interval => { if (DateTime.Compare(interval, DateTimeUtil.UtcToBrasilia()) < 0) { exclude.Add(interval); } else if ((DateTime.Compare(interval, (DateTime)workHours.StartInterval) >= 0) && (DateTime.Compare(interval, (DateTime)workHours.EndInterval) < 0)) { // se estiver dentro do horário de intervalo exclude.Add(interval); } else if (schedulings.Any(x => DateTime.Compare(x.StartTime, interval) <= 0) && schedulings.Any(x => DateTime.Compare(x.EndTime, interval) > 0)) { // se estiver dentro fo horário de algum agendamento do dia exclude.Add(interval); } }); exclude.ForEach(item => intervals.Remove(item)); response.Success = true; response.Result = intervals; response.Message = "Horários selecionados com sucesso!"; } catch (Exception e) { response.Message = "Ocorreu um erro ao calcular a lista de horários"; } return(response); }
public ResponseModel GetAvailableEmployeeWorkHours(DateTime date, Employee employee, Domain.Entities.Services service) { var response = new ResponseModel(); try { var workHours = _employeeWorkHoursRepository.GetWorkHoursByDateAndEmployeeId(date, employee.EmployeeId); var schedulings = _schedulingRepository.GetDaySchedulingsByEmployee(employee.EmployeeId, date); DateTime StartTime = workHours.StartHour; DateTime EndTime = workHours.EndHour; List <DateTime> intervals = new List <DateTime>(); while (StartTime <= EndTime.AddMinutes(service.DurationMinutes * -1)) { StartTime = StartTime.AddMinutes(service.DurationMinutes); intervals.Add(StartTime); } List <DateTime> exclude = new List <DateTime>(); intervals.ForEach(interval => { // se estiver dentro do horário de intervalo if ((DateTime.Compare(interval, (DateTime)workHours.StartInterval) >= 0) && (DateTime.Compare(interval, (DateTime)workHours.EndInterval) < 0)) { exclude.Add(interval); } // se estiver dentro fo horário de algum agendamento do dia if (schedulings.Any(x => DateTime.Compare(x.StartTime, interval) <= 0) && schedulings.Any(x => DateTime.Compare(x.EndTime, interval) > 0)) //if (schedulings.Any(x => x.StartTime <= interval) && schedulings.Any(x => x.EndTime > interval)) { exclude.Add(interval); } }); exclude.ForEach(item => intervals.Remove(item)); response.Success = true; response.Result = intervals; response.Message = "Horários selecionados com sucesso!"; }catch (Exception e) { response.Message = "Ocorreu um erro ao calcular a lista de horários"; } return(response); }
public ResponseModel CreateScheduling(CreateSchedulingModel model) { var resp = new ResponseModel(); try { Client client = _clientRepository.GetClientByUserId(Guid.Parse(model.UserId)); if (client == null) { resp.Message = "Não foi possível encontrar o cliente"; return(resp); } Employee employee = _employeeRepository.GetById(Guid.Parse(model.EmployeeId)); if (employee == null) { resp.Message = "Não foi possível encontrar o funciónário"; return(resp); } Domain.Entities.Services service = _serviceRepository.GetById(Guid.Parse(model.ServiceId)); if (service == null) { resp.Message = "Não foi possível encontrar o serviço"; return(resp); } DateTime startTime; if (!DateTime.TryParse(model.StartTime, out startTime)) { resp.Message = "Start time inválida"; return(resp); } DateTime endTime; if (!DateTime.TryParse(model.EndTime, out endTime)) { resp.Message = "End time inválida"; return(resp); } Scheduling newScheduling = new Scheduling { SchedulingId = Guid.NewGuid(), EmployeeId = Guid.Parse(model.EmployeeId), ClientId = client.ClientId, ServiceId = Guid.Parse(model.ServiceId), StartTime = startTime, EndTime = endTime, CreatedAt = DateTimeUtil.UtcToBrasilia(), LastUpdatedAt = DateTimeUtil.UtcToBrasilia() }; _schedulingRepository.Add(newScheduling); Scheduling scheduling = _schedulingRepository.GetSchedulingByIdComplete(newScheduling.SchedulingId); if (scheduling == null) { resp.Message = "Falha ao realizar o agendamento"; return(resp); } resp.Success = true; resp.Message = "Agendamento realizado com sucesso!"; resp.Result = SchedulingToGetSchedulingModel(scheduling); } catch (Exception e) { resp.Message = $"Não foi possível realizar o agendamento. {e.Message}"; } return(resp); }