daminko
daminko
CC#
Created by daminko on 5/6/2024 in #help
✅ Websocket
Hello, I want to know how can I fire an event from asp.net core backend event to get the positions from the flutter app of all the my users even if the app isn't opened
14 replies
CC#
Created by daminko on 4/26/2024 in #help
an error occured while sending an update request
This my method :
public async Task<IActionResult> Update([FromRoute] string matricule, [FromBody] UpdateUserRequestDTO updateDto)
{


var user = await _utilisateurService.GetByMatriculeAsync(matricule);
if (user == null)
{
return NotFound();
}

if (user.Data.Role == "Transporteur")
{
var transporteur = await _transporteurService.GetByMatriculeAsync(user.Data);
if (transporteur == null)
{
return NotFound("Transporteur not found");
}

if (transporteur.Data!.VehiculeId != updateDto.VehiculeId)
{
var switchNew = await _vehiculeService.SwitchLibre(updateDto.VehiculeId!);
var switchOld = await _vehiculeService.SwitchLibre(transporteur.Data.VehiculeId!);

if (!switchNew.Success || !switchOld.Success)
{
// Roll back the switch operation if either fails
if (!switchNew.Success)
{
await _vehiculeService.SwitchLibre(transporteur.Data.VehiculeId!);
}
if (!switchOld.Success)
{
await _vehiculeService.SwitchLibre(updateDto.VehiculeId!);
}
return BadRequest("Failed to switch vehicle availability");
}
}

var updatedTransporteur = await _transporteurService.UpdateTransporteur(updateDto, matricule);
return updatedTransporteur.Success ? Ok(updatedTransporteur.Data) : BadRequest(updatedTransporteur.Message);
}

else
{
return BadRequest("Invalid role");
}
}
public async Task<IActionResult> Update([FromRoute] string matricule, [FromBody] UpdateUserRequestDTO updateDto)
{


var user = await _utilisateurService.GetByMatriculeAsync(matricule);
if (user == null)
{
return NotFound();
}

if (user.Data.Role == "Transporteur")
{
var transporteur = await _transporteurService.GetByMatriculeAsync(user.Data);
if (transporteur == null)
{
return NotFound("Transporteur not found");
}

if (transporteur.Data!.VehiculeId != updateDto.VehiculeId)
{
var switchNew = await _vehiculeService.SwitchLibre(updateDto.VehiculeId!);
var switchOld = await _vehiculeService.SwitchLibre(transporteur.Data.VehiculeId!);

if (!switchNew.Success || !switchOld.Success)
{
// Roll back the switch operation if either fails
if (!switchNew.Success)
{
await _vehiculeService.SwitchLibre(transporteur.Data.VehiculeId!);
}
if (!switchOld.Success)
{
await _vehiculeService.SwitchLibre(updateDto.VehiculeId!);
}
return BadRequest("Failed to switch vehicle availability");
}
}

var updatedTransporteur = await _transporteurService.UpdateTransporteur(updateDto, matricule);
return updatedTransporteur.Success ? Ok(updatedTransporteur.Data) : BadRequest(updatedTransporteur.Message);
}

else
{
return BadRequest("Invalid role");
}
}
4 replies
CC#
Created by daminko on 4/21/2024 in #help
I need help with identity and roles
No description
17 replies
CC#
Created by daminko on 4/20/2024 in #help
Entity framework exception while creating a many to many relation
Hello everyone, I've been trying to make a many to many relation between two classes Voyage and Transporteur. these are the Three classes:
c#
public class Transporteur : IdentityUser
{
public string Nom { get; set; } = string.Empty;
public string Prenom { get; set; } = string.Empty;

public Vehicule? Vehicule { get; set; }
public string? VehiculeId { get; set; } = string.Empty;
public bool ExterneDuService { get; set; } = false;
public List<Voyage> Voyages { get; } = [];
public ICollection<TransporteurVoyage> TransporteurVoyages { get; } = [];
}
****************************************************
public class Voyage
{
[Key]
public string IdVoyage { get; set; } = string.Empty;
public DateTime DateSortieBon { get; set; }
public DateTime DateDepartVoyage { get; set; }

public string Etat { get; set; } = string.Empty;
//Demandeur
public Demandeur Demandeur { get; set; } = null!;
public string DemandeurId { get; set; } = string.Empty;
//public ICollection<Utilisateur> Utilisateurs { get; set; } = new List<Utilisateur>();
public Magasinier Magasinier { get; set; } = null!;
public string IdMagasinier { get; set; } = string.Empty;
public TypeVoyage TypeVoyage { get; set; } = null!;
public int TypeVoyageId { get; set; }
public List<Transporteur> Transporteurs { get; } = [];
public ICollection<TransporteurVoyage> TransporteurVoyages { get; } = [];


}
********************************************************************
public class TransporteurVoyage
{
public string TransporteurId { get; set; } = string.Empty;
public string VoyageId { get; set; } = string.Empty;
public bool Panne { get; set; } = false;
public Voyage Voyage { get; set; }
public Transporteur Transporteur { get; set; }

}
c#
public class Transporteur : IdentityUser
{
public string Nom { get; set; } = string.Empty;
public string Prenom { get; set; } = string.Empty;

public Vehicule? Vehicule { get; set; }
public string? VehiculeId { get; set; } = string.Empty;
public bool ExterneDuService { get; set; } = false;
public List<Voyage> Voyages { get; } = [];
public ICollection<TransporteurVoyage> TransporteurVoyages { get; } = [];
}
****************************************************
public class Voyage
{
[Key]
public string IdVoyage { get; set; } = string.Empty;
public DateTime DateSortieBon { get; set; }
public DateTime DateDepartVoyage { get; set; }

public string Etat { get; set; } = string.Empty;
//Demandeur
public Demandeur Demandeur { get; set; } = null!;
public string DemandeurId { get; set; } = string.Empty;
//public ICollection<Utilisateur> Utilisateurs { get; set; } = new List<Utilisateur>();
public Magasinier Magasinier { get; set; } = null!;
public string IdMagasinier { get; set; } = string.Empty;
public TypeVoyage TypeVoyage { get; set; } = null!;
public int TypeVoyageId { get; set; }
public List<Transporteur> Transporteurs { get; } = [];
public ICollection<TransporteurVoyage> TransporteurVoyages { get; } = [];


}
********************************************************************
public class TransporteurVoyage
{
public string TransporteurId { get; set; } = string.Empty;
public string VoyageId { get; set; } = string.Empty;
public bool Panne { get; set; } = false;
public Voyage Voyage { get; set; }
public Transporteur Transporteur { get; set; }

}
39 replies