public ActionResult Inscription(User user) { AddClientSession(new Client { Id = 1 }); return RedirectToRoute("Frontend_compte_index"); }
/// <summary> /// Permet d'ajouter l'user à la session /// </summary> /// <param name="user">User à ajouter en session</param> /// <returns>bool</returns> public bool AddUserSession(User user = null) { try { if (user.IsNull()) return false; FormsAuthentication.SetAuthCookie(user.Id.ToString(), false); return true; } catch (Exception) { return false; } }
public AdministrateurFranchise UserToClient(User user = null) { try { if (user.IsNull()) return null; return (AdministrateurFranchise)user; } catch (Exception) { return null; } }
/// <summary> /// Permet de caster un User en Employe /// </summary> /// <param name="user">User à caster</param> /// <returns>Employe</returns> public Employe UserToEmploye(User user = null) { try { if (user.IsNull()) return null; return (Employe)user; } catch (Exception) { return null; } }
private bool AccessSalonManager(int? idSalon, User user = null) { try { if (user.IsNull() || idSalon.IsNull()) return false; var manager = (Manager)user; if (manager.IsNull()) return false; return manager.IdSalon == idSalon; } catch (Exception) { return false; } }
/// <summary> /// Permet de savoir si l'employé à accés au salon /// </summary> /// <param name="idSalon">Id du salon</param> /// <param name="user">L'employé</param> /// <returns>bool</returns> private bool AccessSalonEmploye(int? idSalon, User user = null) { try { if (user.IsNull() || idSalon.IsNull()) return false; var employe = (Employe)user; if (employe.IsNull()) return false; return Salons.Where(s => s.Id == idSalon) .SelectMany(s => s.ListeEmployes). FirstOrDefault(e => e.Id == employe.Id) .IsNotNull(); } catch (Exception) { return false; } }
/// <summary> /// Permet de savoir si un administrateur franchise a accés au salon /// </summary> /// <param name="idSalon">Id du salon</param> /// <param name="user">Administrateur</param> /// <returns>bool</returns> private bool AccessSalonAdministrateurFranchise(int? idSalon, User user = null) { try { if (user.IsNull() || idSalon.IsNull()) return false; var admin = (AdministrateurFranchise)user; if (admin.IsNull()) return false; return Franchises.Where(f => f.Id == admin.IdFranchise) .SelectMany(f => f.Salons). FirstOrDefault(s => s.Id == idSalon) .IsNotNull(); } catch (Exception) { return false; } }
/// <summary> /// Permet de savoir si un user peut accéder au salon /// </summary> /// <param name="idSalon">Id du salon</param> /// <param name="user">L'user</param> /// <returns>bool</returns> public bool AccessSalon(int? idSalon, User user = null) { try { if (idSalon.IsNull() || user.IsNull() || user.IsClient()) return false; if (user.IsSuperAdmin()) return true; if (user.IsAdministrateurFranchise()) return AccessSalonAdministrateurFranchise(idSalon, user); if (user.IsEmploye()) return AccessSalonEmploye(idSalon, user); if (user.IsManager()) return AccessSalonManager(idSalon, user); return false; } catch (Exception) { return false; } }