public IActionResult CarIsBeingUsedByOtherSolicitation([FromBody] CarIsBeingUsedByOtherSolicitation transport) { transport.UserId = GetIdUser(); var result = _transportService.CarIsBeingUsedByOtherSolicitation(transport); if (!result.IsSuccess) { return(BadRequest(result)); } return(Ok(result.Response)); }
public ServiceResult <Boolean> CarIsBeingUsedByOtherSolicitation( CarIsBeingUsedByOtherSolicitation transport ) { var startDate = DateTime.Parse(transport.StartDate.Day + "/" + transport.StartDate.Month + "/" + transport.StartDate.Year); var endDate = DateTime.Parse(transport.StartDate.Day + "/" + transport.StartDate.Month + "/" + transport.StartDate.Year) .AddDays(transport.Days); //coninciden en la fecha y el transporte. var destinies = _dataContext.Destinies .Include(c => c.SolicitationSubsidy) .Where(x => x.TransportId == transport.Id && !(x.StartDate.AddDays(x.Days) < startDate || x.StartDate > endDate) ); var resultDates = _solicitationSubsidyService.OverlapingDates(new OverlapingDatesAndTransportsDto() { Days = transport.Days, StartDateDatetime = startDate, EndDateDatetime = endDate, UserId = transport.UserId }); foreach (var destiny in destinies) { var stateSolicitation = _dataContext.SolicitationStates .Include(x => x.State) .Include(s => s.SolicitationSubsidy) .Where(x => x.SolicitationSubsidyId == destiny.SolicitationSubsidyId) .OrderByDescending(q => q.ChangeDate).FirstOrDefault();//obtengo el estado de la solicitud //si el estado de la solicitud, no es reintegro, no es comisión //almacenada en la DB fue enviada o aceptada if ((stateSolicitation.State.Id == State.Sent || stateSolicitation.State.Id == State.Accepted) && !destiny.SolicitationSubsidy.IsRefund && !stateSolicitation.SolicitationSubsidy.IsCommission) { if (!resultDates.Response) { var transp = _dataContext.Transports.FirstOrDefault(c => c.Id == destiny.TransportId); resultDates = new ServiceResult <bool>(true); resultDates.AddError(NotificationType.Error.ToString(), "El transporte " + transp.Brand + "-" + transp.Model + " ya fue solicitado."); } }//si es destino almacenado actualmente es una comisión. else if ((stateSolicitation.State.Id == State.Sent || stateSolicitation.State.Id == State.Accepted) && !destiny.SolicitationSubsidy.IsRefund && stateSolicitation.SolicitationSubsidy.IsCommission) { //pregunto si el usuario es parte de esa comisión. var solicitationUser = _dataContext.SolicitationSubsidies .Where(x => x.UserId == transport.UserId && x.IsCommission && x.RandomKey.Equals(stateSolicitation.SolicitationSubsidy.RandomKey) ).ToList(); //no es parte de la comision, ni es un reintegro. if (solicitationUser.Count == 0) { var transp = _dataContext.Transports.FirstOrDefault(c => c.Id == destiny.TransportId); resultDates.AddError(NotificationType.Error.ToString(), "El transporte " + transp.Brand + "-" + transp.Model + " ya fue solicitado."); } } } return(resultDates); }