public async Task <IActionResult> Payment([FromBody] ReserveTimeDTO reserveData, int userId) { try { //var token = _httpClientHelper.GetAsync<string>() // Falta Payment.Utilitis de Adair //var si = new SignInDto() { Email = this._paymentSettings.Value.UserPayment, Password = this._paymentSettings.Value.PasswordPayment }; //var response = await _httpClientHelper.PostAsync<Result<AuthenticationResult>, SignInDto>(si, this._paymentSettings.Value.AutenticateUri); //if (!response.IsSuccess) //{ // return BadRequest("El Pago no se pudo realizar, contacte al Administrador"); // Error por login con Payment Adalid //} //var token = response.Value.Token; //response return(Ok()); } catch (Exception ex) { new FileManagerHelper().RecordLogFile(MethodBase.GetCurrentMethod().ReflectedType.FullName, reserveData, ex); return(BadRequest(this._appSettings.Value.ServerError)); //this._config.GetSection("AppSettings:ServerError").Value); } }
public async Task <IActionResult> Reserving([FromBody] ReserveTimeDTO reserveData, int userId) { try { if (reserveData.Date.Length != 8) { return(BadRequest("Formato de Fecha Incorrecto. (YYYYMMDD)")); } var y = Convert.ToInt32(reserveData.Date.Substring(0, 4)); var m = Convert.ToInt32(reserveData.Date.Substring(4, 2)); var d = Convert.ToInt32(reserveData.Date.Substring(6, 2)); if (y < 2020 || m > 12 || d > 31) { return(BadRequest("Fecha incorrecta.")); } if (reserveData.Hour.Length != 4) { return(BadRequest("Formato de Hora Incorrecto. (HHMM)")); } var HH = Convert.ToInt32(reserveData.Hour.Substring(0, 2)); var mm = Convert.ToInt32(reserveData.Hour.Substring(2)); if (HH > 24 || mm > 59) { return(BadRequest("Hora incorrecta.")); } var memberDb = await this._repo.GetMember(null, null, userId); if (memberDb == null) { return(BadRequest("Socio no encontrado.")); } if (!memberDb.User.IsActive) { return(BadRequest("Socio Bloqueado.")); } var settings = await this._repo.GetGeneralSettings(); // var time = reserveData.Hour.Split(':'); // var reserveTime = new DateTime(reserveData.Date.Year, reserveData.Date.Month, reserveData.Date.Day, Convert.ToInt32(time[0]), Convert.ToInt32(time[1]), 0); var reserveTime = new DateTime(y, m, d, HH, mm, 0); // date if (reserveTime > memberDb.MembershipExpiration) { return(BadRequest("Membrecia Vencida.")); } if (reserveTime < DateTime.Now) { return(BadRequest("La reservación no puede ser en el pasado")); } var minTimeToReserve = DateTime.Now.AddHours(settings.ScheduleChangeHours); if (reserveTime < minTimeToReserve) { return(BadRequest("Se debe reservar con " + settings.ScheduleChangeHours.ToString() + " horas de anticipación")); } var scheduleSettings = JsonConvert.DeserializeObject <List <ScheduleDaySettings> >(settings.ScheduledWeek); var hourReservation = reserveData.Hour.Substring(0, 2) + ":"; hourReservation += reserveData.Hour.Substring(2); var foundHour = false; for (int s = 0; s < scheduleSettings.Count; s++) { if (scheduleSettings[s].Day.ToLower() == reserveTime.ToString("dddd").ToLower()) { for (int h = 0; h < scheduleSettings[s].RangeDates.Count; h++) { if (scheduleSettings[s].RangeDates[h].StarHour == hourReservation) // reserveData.Hour) { foundHour = true; break; } } } } if (!foundHour) { return(BadRequest("Horario de reservación invalido")); } var authorizedCapacity = await this._repo.GetCurrentAuthorizedCapacity(reserveTime); var currentOccupation = this._repo.GetCurrentOccupationHour(reserveTime); if (authorizedCapacity <= currentOccupation) { return(BadRequest("Horario saturado, Favor de seleccionar otra hora.")); } var userBookedDay = this._repo.GetUserBookedDay(memberDb.User.Id, reserveTime); var newBooked = new UserScheduling() { Schedule = reserveTime, User = memberDb.User, IsAttended = false }; this._repo.Add(newBooked); if (userBookedDay != null) // (userBookedDay.Result != null) { this._repo.Remove(userBookedDay); } // Validar vigencia? // Validar Bloqueo? // Y Validar el Usuario // Y Validar el tiempo permitido para hacer cambios // Y Validar que la fecha no sea menor a hoy // Y Validar que la Hora de reserva se encuentre en la configuracion. // Y Validar la disponibilidad // hacer la reservacion // Si tiene reservacion para ese mismo dia, eliminarla. // Regresar la disponibilidad del dia? await this._repo.SaveAll(); //var scheduledDay = this._repo.GetBookedDay(reserveTime); // var currentAuthorizedCapacity = await this._repo.GetCurrentAuthorizedCapacity(reserveTime); currentOccupation = this._repo.GetCurrentOccupationHour(reserveTime); var availability = authorizedCapacity - currentOccupation; /* * var sdh = scheduledDay.FirstOrDefault(d => d.Schedule == reserveTime); * if (sdh != null) * { * availability = authorizedCapacity - sdh.Count; * // if (availability < settings.NotificationCapacity) * // hd.Capacity = availability.ToString(); * } */ return(Ok(availability)); } catch (Exception ex) { new FileManagerHelper().RecordLogFile(MethodBase.GetCurrentMethod().ReflectedType.FullName, reserveData, ex, "UserId : " + userId.ToString()); return(BadRequest(this._appSettings.Value.ServerError)); } }