/// <summary> /// Fonction retournant tous les quizz dans une liste de Quizz /// Fonctionne avec une fluentQuerry /// </summary> /// <returns>Retourne tous les quizz</returns> public List <QuizzViewModel> GetAllQuizz() { List <QuizzViewModel> desQuizz = new List <QuizzViewModel>(); using (FilRougeDBContext db = new FilRougeDBContext()) { try { IEnumerable <Quizz> fluentQuery = db.Quizz.Select(e => e).ToList(); if (fluentQuery.Count() == 0) { throw new ListQuizzEmpty("La liste des quizz est vide"); } foreach (var item in fluentQuery) { desQuizz.Add(item.MapToQuizzViewModel()); } } catch (ListQuizzEmpty lqe) { throw new ListQuizzEmpty(lqe.Message); } } return(desQuizz); }
/// <summary> /// Fonction retournant tous les quizz dans une liste de Quizz /// Fonctionne avec une fluentQuerry /// </summary> /// <returns>Retourne tous les quizz</returns> public List <Quizz> GetAllQuizz() { List <Quizz> desQuizz = new List <Quizz>(); FilRougeDBContext db = new FilRougeDBContext(); try { IQueryable <Quizz> fluentQuery = db.Quizz.Select(e => e); if (fluentQuery.Count() == 0) { throw new ListQuizzEmpty("La liste des quizz est vide"); } foreach (var item in fluentQuery) { desQuizz.Add(item); } db.Dispose(); } catch (ListQuizzEmpty) { db.Dispose(); } return(desQuizz); }
private void InsertTypeQuestion(FilRougeDBContext context) { //saisie des 4 types //---saisie libre context.TypeQuestion.AddOrUpdate(new TypeQuestion() { TypeQuestionId = (int)AnswerTypeEnum.SaisieLibre, NameType = AnswerTypeEnum.SaisieLibre.ToString() }); //---choix unique context.TypeQuestion.AddOrUpdate(new TypeQuestion() { TypeQuestionId = (int)AnswerTypeEnum.ChoixUnique, NameType = AnswerTypeEnum.ChoixUnique.ToString() }); //---choix multiple context.TypeQuestion.AddOrUpdate(new TypeQuestion() { TypeQuestionId = (int)AnswerTypeEnum.ChoixMultiple, NameType = AnswerTypeEnum.ChoixMultiple.ToString() }); //---saisie code context.TypeQuestion.AddOrUpdate(new TypeQuestion() { TypeQuestionId = (int)AnswerTypeEnum.SaisieCode, NameType = AnswerTypeEnum.SaisieCode.ToString() }); }
public Technology GetTechnologyById(int id) { FilRougeDBContext db = new FilRougeDBContext(); var fluentQuery = db.Technology.Single(e => e.TechnoId == id); db.Dispose(); return(fluentQuery); }
/// <summary> /// Methode d'ajout d'une technologie /// </summary> /// <param name="technology"></param> public void AddTechnology(Technology technology) { using (var dbContext = new FilRougeDBContext()) { dbContext.Technologies.Add(technology); dbContext.SaveChanges(); } }
public void AddTypeQuestion(TypeQuestion typeQuestion) { using (var dbContext = new FilRougeDBContext()) { dbContext.TypeQuestion.Add(typeQuestion); dbContext.SaveChanges(); } }
} //Constructeur #region Methods /// <summary> /// Méthode permettant d'obtenir un quizz en fonction de son id /// Fonctionne avec une fluentQuerry /// </summary> /// <param name="id">l'ID du quizz (sa clé primaire)</param> /// <returns>Retourne un objet Quizz</returns> public QuizzViewModel GetQuizz(int id) { using (FilRougeDBContext db = new FilRougeDBContext()) { var quizz = db.Quizz.Single(e => e.QuizzId == id); return(quizz.MapToQuizzViewModel()); } }
public List <UserReponse> GetQuizzUserAnswer(int id) { using (FilRougeDBContext db = new FilRougeDBContext()) { var userReponse = db.UserReponse.Include(u => u.Reponse).Where(q => q.QuizzId == id).ToList(); return(userReponse); } }
/// <summary> /// Création d'un Quizz /// </summary> /// <param name="difficultyid"></param> /// <param name="technoid"></param> /// <param name="userid"></param> /// <param name="nomuser"></param> /// <param name="prenomuser"></param> /// <param name="questionlibre"></param> /// <param name="nombrequestions"></param> public Quizz CreateQuizz(QuizzViewModel quizzViewModel, int difficultymasterid) { Quizz unQuizz = null; using (FilRougeDBContext db = new FilRougeDBContext()) { var quizz = quizzViewModel.MapToQuizz(); List <Questions> questionsQuizz = AddQuestionToQuizz(quizz.QuestionLibre, quizz.NombreQuestion, quizz.TechnologyId, difficultymasterid, db); int timer = quizz.Timer; try { //TODO creer un viewbag des users => authorize create quizz // verifier paramètres de création d'un quizz Contact creatingQuizzContact = db.Users.Single(e => e.Id == quizz.ContactId); Difficulty difficultyQuizz = db.Difficulties.Single(e => e.DifficultyId == difficultymasterid); Technology technoQuizz = db.Technologies.Single(e => e.TechnoId == quizz.TechnologyId); unQuizz = new Quizz { ContactId = creatingQuizzContact.Id, DifficultyId = difficultymasterid, TechnologyId = quizz.TechnologyId, Timer = quizz.Timer, PrenomUser = quizz.PrenomUser, NomUser = quizz.NomUser, NombreQuestion = quizz.NombreQuestion, EtatQuizz = quizz.EtatQuizz, QuestionLibre = quizz.QuestionLibre, Contact = creatingQuizzContact, Difficulty = difficultyQuizz, Questions = questionsQuizz, Technology = technoQuizz }; db.Quizz.Add(unQuizz); db.SaveChanges(); db.Dispose(); } catch (AlreadyInTheQuestionsList e) { Console.WriteLine(e.Message); db.Dispose(); } catch (NoQuestionsForYou e) { Console.WriteLine(e.Message); db.Dispose(); } catch (Exception e) { Console.WriteLine(e.Message); } } return(unQuizz); }
/// <summary> /// Edition d'un type de question /// </summary> /// <param name="typeQuestion"></param> /// <returns></returns> public TypeQuestion EditTypeQuestion(TypeQuestion typeQuestion) { using (var dbContext = new FilRougeDBContext()) { dbContext.Entry(typeQuestion).State = EntityState.Modified; dbContext.SaveChanges(); } return(typeQuestion); }
/// <summary> /// Retourne le type de question par son "Id" /// </summary> /// <param name="id"></param> /// <returns></returns> public TypeQuestion GetTypeQuestion(int?id) { var typeQuestion = new TypeQuestion(); using (var dbContext = new FilRougeDBContext()) { typeQuestion = dbContext.TypeQuestion.Find(id); } return(typeQuestion); }
/// <summary> /// Retourne la technologie par son "Id" /// </summary> /// <param name="id"></param> /// <returns></returns> public Technology GetTechnology(int?id) { var technolgie = new Technology(); using (var dbContext = new FilRougeDBContext()) { technolgie = dbContext.Technologies.Find(id); } return(technolgie); }
public int AddReponsesToQuestion(int id, List <Reponses> reponses) { using (var db = new FilRougeDBContext()) { var questionAddReponse = db.Questions.Find(id); questionAddReponse.Reponses = reponses; // ajout de la liste des réponses à la question int nbRes = db.SaveChanges(); return(nbRes); } }
/// <summary> /// Retourne la liste des technologies /// </summary> /// <returns></returns> public List <Technology> GetAllTechnologies() { var listTechnologies = new List <Technology>(); using (var dbContext = new FilRougeDBContext()) { listTechnologies = dbContext.Technologies.ToList(); } return(listTechnologies); }
/// <summary> /// Suppression d'un type de question /// </summary> /// <param name="id"></param> public void RemoveTypeQuestion(int id) { var typeQuestion = new TypeQuestion(); using (var dbContext = new FilRougeDBContext()) { typeQuestion = dbContext.TypeQuestion.Find(id); dbContext.TypeQuestion.Remove(typeQuestion); dbContext.SaveChanges(); } }
/// <summary> /// Retourne la List de type de question /// </summary> /// <returns></returns> public List <TypeQuestion> GetAllTypeQuestion() { var listTypeQuestion = new List <TypeQuestion>(); using (var dbContext = new FilRougeDBContext()) { listTypeQuestion = dbContext.TypeQuestion.ToList(); } return(listTypeQuestion); }
/// <summary> /// Suppression d'une technologie par son id /// </summary> /// <param name="id"></param> public void RemoveTechnology(int id) { var technologie = new Technology(); using (var dbContext = new FilRougeDBContext()) { technologie = dbContext.Technologies.Find(id); dbContext.Technologies.Remove(technologie); dbContext.SaveChanges(); } }
/// <summary> /// Edition d'une technologie par son "Id" /// </summary> /// <param name="id"></param> /// <returns></returns> public Technology EditTechnology(Technology technology) { var technolgie = new Technology(); using (var dbContext = new FilRougeDBContext()) { dbContext.Entry(technology).State = EntityState.Modified; dbContext.SaveChanges(); } return(technolgie); }
/// <summary> /// Cette fonction permet d'obtenir toutes les technologies /// Fonctionne avec une fluentQuerry /// </summary> /// <returns>Retourne une liste d'objets Technologies</returns> public List <Technology> GetTechnologies() { List <Technology> desTechnologies = new List <Technology>(); //FilRougeDBContext db = new FilRougeDBContext(); using (var db = new FilRougeDBContext()) { desTechnologies = db.Technologies.Select(e => e).ToList(); } return(desTechnologies); }
public string GetRoleName(string id) { using (var db = new FilRougeDBContext()) { var role = db.Roles.FirstOrDefault(r => r.Id == id); if (role != null) { return(role.Name); } } return(""); }
private void InsertRole(FilRougeDBContext context) { context.Roles.AddOrUpdate(r => r.Name, new IdentityRole() { Name = "Admin" }); context.Roles.AddOrUpdate(r => r.Name, new IdentityRole() { Name = "Agent" }); }
public DifficultyMasterViewModel GetDifficultyById(int difficultyId) { var difficultyViewModel = new DifficultyMasterViewModel(); using (var dbContext = new FilRougeDBContext()) { var difficultyEntities = dbContext.Difficulties.Find(difficultyId); difficultyViewModel = difficultyEntities.MapToDifficultyMasterViewModel(); } return(difficultyViewModel); }
public int AddDifficulty(Difficulty difficulty) { int id = 0; using (var dbContext = new FilRougeDBContext()) { dbContext.Difficulties.Add(difficulty); dbContext.SaveChanges(); id = difficulty.DifficultyId; } return(id); }
/// <summary> /// Récuperer un contact /// </summary> /// <param name="id"></param> /// <returns></returns> public ContactViewModel GetContactById(string id) { var contactViewModel = new ContactViewModel(); using (var db = new FilRougeDBContext()) { var contact = db.Users.Find(id); contactViewModel = contact.MapToContactViewModel(); contactViewModel.RoleName = GetRoleName(contact.Roles.Count > 0 ? contact.Roles.FirstOrDefault().RoleId : ""); } return(contactViewModel); }
/// <summary> /// Retourne une question par son "ID" /// </summary> /// <param name="id"></param> /// <returns></returns> public QuestionViewModel GetQuestion(int?id) { var question = new Questions(); using (var dbContext = new FilRougeDBContext()) { question = dbContext.Questions .Include("Technology").Include("TypeQuestion").Include("Difficulty").Include("Reponses") .Where(q => q.QuestionId == id) .Select(q => q).First(); } return(question.MapToQuestionsViewModel()); }
public int AddDifficulty(DifficultyMasterViewModel difficultyViewModel) { int id = 0; using (var dbContext = new FilRougeDBContext()) { var difficulty = difficultyViewModel.MapToDifficultyMaster(); dbContext.Difficulties.Add(difficulty); dbContext.SaveChanges(); id = difficulty.DifficultyId; } return(id); }
/// <summary> /// Cette méthode permet de récupérer toutes les difficultés /// Fonctionne avec une fluentQuerry /// </summary> /// <returns>Retourne une liste d'objets Diffulties</returns> public List <DifficultyRate> GetDifficulties() { List <DifficultyRate> desDifficulties = new List <DifficultyRate>(); FilRougeDBContext db = new FilRougeDBContext(); var fluentQuery = db.DifficultyMaster.Select(e => e); foreach (var item in fluentQuery) { desDifficulties.Add(item); } db.Dispose(); return(desDifficulties); }
public QuizzAnswerReponsesViewModel GetQuizzAnswer(int id) { using (FilRougeDBContext db = new FilRougeDBContext()) { var quizz = db.Quizz.Include(q => q.Questions) .Include(q => q.Technology) .Include(q => q.Difficulty) .Include(q => q.Contact) .Single(e => e.QuizzId == id).MapToQuizzAnswerReponsesViewModel(); return(quizz); } }
/// <summary> /// Cette fonction permet d'obtenir toutes les technologies /// Fonctionne avec une fluentQuerry /// </summary> /// <returns>Retourne une liste d'objets Technologies</returns> public List <Technology> GetTechnologies() { List <Technology> desTechnologies = new List <Technology>(); FilRougeDBContext db = new FilRougeDBContext(); var fluentQuery = db.Technology.Select(e => e); foreach (var item in fluentQuery) { desTechnologies.Add(item); } db.Dispose(); return(desTechnologies); }
public int EditDifficulty(DifficultyMasterViewModel difficultyViewModel) { var id = 0; using (var dbContext = new FilRougeDBContext()) { var difficulty = dbContext.Difficulties.Find(difficultyViewModel.DiffMasterId); difficulty.DifficultyId = difficultyViewModel.DiffMasterId; difficulty.DifficultyName = difficultyViewModel.DiffMasterName; dbContext.Entry(difficulty).State = EntityState.Modified; dbContext.SaveChanges(); id = difficulty.DifficultyId; } return(id); }