public ActionResult Details(int id) { GroupeRepository Gr = new GroupeRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); DetailsGroupModel Gwm = MapToDBModel.GroupToDetails(Gr.GetOneWithInfos(id)); ViewBag.Current = "Groupe"; return(View()); }
public ActionResult Edit(int id) { GroupeRepository Gr = new GroupeRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); Groupe G = Gr.GetOne(id); //Entity EditGroupModel Gm = MapToDBModel.GroupToEditGroupModel(G); ViewBag.Current = "Groupe"; return(View(Gm)); }
public ActionResult Admin() { GroupeRepository GR = new GroupeRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); int id = SessionUtils.ConnectedUser.Id; List <GroupModel> Lgm = GR.GetAllFromMembre(id, true).Select(g => MapToDBModel.GroupToGroupModel(g)).ToList(); ViewBag.Current = "Groupe Admin"; return(View(Lgm)); }
public ActionResult Form() { PaysRepository mr = new PaysRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); //select comme for //ici je retraduit le mapper de maptoDBModel a la requeque que j'ai fait List <PaysModel> ListePays = mr.GetCountries().Select(c => MapToDBModel.PaysToPaysModel(c)).ToList(); return(View(ListePays)); }
// GET: Membre/Bien public ActionResult DisplayProperties() { MembreRepository mr = new MembreRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); int id = SessionUtils.ConnectedUser.Id; //select comme for //ici je retraduit le mapper de maptoDBModel a la requeque que j'ai fait List <BienModel> ListeBien = mr.LoadBien(id).Select(c => MapToDBModel.BienToBienModel(c)).ToList(); return(View(ListeBien)); }
// GET: Membre/Group public ActionResult Index() { if (!SessionUtils.IsConnected) { return(RedirectToAction("Login", new { controller = "Home", area = "" })); } GroupeRepository Gr = new GroupeRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); int id = SessionUtils.ConnectedUser.Id; List <GroupeModel> Gmodel = Gr.GetGroupeMembre(id).Select(g => MapToDBModel.GroupeToGroupeModel(g)).ToList();; return(View(Gmodel)); }
public ActionResult AddProperties() { PaysRepository mr = new PaysRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); //select comme for //ici je retraduit le mapper de maptoDBModel a la requeque que j'ai fait List <PaysModel> ListePays = mr.GetCountries().Select(item => MapToDBModel.PaysToPaysModel(item)).ToList(); OptionRepository or = new OptionRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); List <OptionModel> ListeOptions = or.GetAll().Select(item => MapToDBModel.OptionToOptionModel(item)).ToList(); return(View()); }
// GET: Membre/Cadeau public ActionResult Index() { if (!SessionUtils.IsConnected) { return(RedirectToAction("Login", new { controller = "Home", area = "" })); } CadeauRepository Cd = new CadeauRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); int id = SessionUtils.ConnectedUser.Id; List <CadeauModel> Cmodel = Cd.GetGiftsMember(id).Select(c => MapToDBModel.CadeauToCadeauModel(c)).ToList(); return(View(Cmodel)); }
public ActionResult Admin() { if (!SessionUtils.IsConnected) { return(RedirectToAction("Login", new { controller = "Home", area = "" })); } GroupeRepository GR = new GroupeRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); int id = SessionUtils.ConnectedUser.Id; List <GroupModel> Lgm = GR.GetAllFromMembre(id, true).Select(g => MapToDBModel.GroupToGroupModel(g)).ToList(); ViewBag.Current = "Groupe Admin"; return(View(Lgm)); }
public ActionResult Create() { EvenementRepository er = new EvenementRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); List <Evenement> ev = er.GetAll().ToList(); List <EventModel> MesEvents = new List <EventModel>(); foreach (Evenement item in ev) { MesEvents.Add(MapToDBModel.EvenementToEventModel(item)); } ViewBag.Current = "Groupe"; return(View(MesEvents)); }
public ActionResult EditAnimal(AnimalModel animM, HttpPostedFileBase Photo) { AnimalRepository aniRepo = new AnimalRepository(ConfigurationManager.ConnectionStrings["My_Asptest_Cnstr"].ConnectionString); if (!ModelState.IsValid) { foreach (ModelState each_modelState in ViewData.ModelState.Values) { foreach (ModelError each_error in each_modelState.Errors) { ViewBag.ErrorMessage += each_error.ErrorMessage + "<br>"; } } return RedirectToAction("Index"); } else { // 1. Ajouter ANIMAL sans photo AnimalModel anMo = mapToVIEWmodels.animalToAnimalModel(aniRepo.insert(MapToDBModel.animalModelToAnimal(animM))); // 2. photo : if (anMo != null) { List<string> listeMIME = new List<string>() { "image/jpeg", "image/png", "image/gif" }; if (!listeMIME.Contains(Photo.ContentType) /*|| photoAnim.ContentLength > 800000*/) { ViewBag.ErrorMessage = "unauthorized extention (choose : png, jpg or gif)"; return View("Index"); } string[] splitPhotoname = Photo.FileName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); string ext = splitPhotoname[splitPhotoname.Length - 1]; string photoNew = anMo.IdAnimal + "animal" + "." + ext; anMo.Photo = photoNew; // saved in DB via mapper string chemin = Server.MapPath("~/photos/animal"); string photoToSave = chemin + "/" + photoNew; Photo.SaveAs(photoToSave); // try catch bool reussi = aniRepo.update(MapToDBModel.animalModelToAnimal(anMo)); if (reussi) { AnimalModel updatedAnModel = mapToVIEWmodels.animalToAnimalModel(aniRepo.getOne(animM.IdAnimal)); SessionUtilisateur.ConnectedUserAnimals.ToList().Add(updatedAnModel); return RedirectToAction("Index", new { controller = "Home", area = "Admin" }); } } return View(ViewBag.Message = "Insersion failed"); } }
public ActionResult Edit(SaveGroupModel Gm) { GroupeRepository Gr = new GroupeRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); Groupe G = MapToDBModel.SaveGroupModelToGroup(Gm); if (Gr.Update(G)) { return(RedirectToAction("index")); } else { ViewBag.Current = "Groupe"; return(View()); //++ message d'erreur au besoin } }
public ActionResult Create(SaveGroupModel SG) { GroupeRepository Gr = new GroupeRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); Groupe G = MapToDBModel.SaveGroupModelToGroup(SG); G = Gr.InsertWithAdmin(G, SessionUtils.ConnectedUser.Id); if (G.Id != 0) { return(RedirectToAction("index")); } else { ViewBag.Current = "Groupe"; return(View()); //++ message d'erreur au besoin } }
public ActionResult Login(LoginModel lm) { // I intanciate a MembreRepository with the connectionstring. // The connectionstring is stored into web.config and i get it with the ConfigurationManager MembreRepository Cr = new MembreRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); //I use the function VerifLogin from the MembreRepository //For use this function, I have to convert The LoginModel to the ProfileModel Mmodel = MapToDBModel.MemberToProfile(Cr.VerifLogin(MapToDBModel.LoginToMember(lm))); if (Mmodel != null) { SessionUtils.ConnectedUser = Mmodel; SessionUtils.IsConnected = true; return(RedirectToAction("Index", new { controller = "Home", area = "Membre" })); } else { ViewBag.ErrorLoginMessage = "Error Login or Password"; return(RedirectToAction("Index", new { controller = "Home", area = "" })); } }
public ActionResult Login(LoginModel m) { //I intanciate a MembreRepository with the connectionstring. // The connectionstring is stored into web.config and i get it with the ConfigurationManager // If you want more information about ConfigurationManager don't forget to use F12. MembreRepository Mr = new MembreRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); //I use the function VerifLogin from the MembreRepository //For use this function, I have to convert The LoginModel to the ProfileModel Mmodel = MapToDBModel.MemberToProfile(Mr.VerifLogin(MapToDBModel.LoginToMembre(m))); if (Mmodel != null) { SessionUtils.ConnectedUser = Mmodel; SessionUtils.IsConnected = true; return(RedirectToAction("Index", new { controller = "Home", area = "Membre" })); } else { ViewBag.ErrorLoginMessage = "Erreur Login/Mot de passe"; return(View()); } }
// GET: Membre/Cadeaux public ActionResult Index() { ViewBag.Current = "Cadeaux"; CadeauRepository CR = new CadeauRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); List <CadeauxModel> Lc = CR.GetCadeauxFromMembre(SessionUtils.ConnectedUser.Id).Select(c => MapToDBModel.CadeauxToCadeauxModel(c)).ToList(); return(View(Lc)); }
//[Required]?? public ViewResult Register(RegisterModel Rm, HttpPostedFileBase ProfilePicture) { //HttpPostedFileBase - Use to retrieve picture uploaded from form //We have to verify the mime type and the image size List <string> matchContentType = new List <string>() { "image/jpeg", "image/png", "image/gif" }; if (!matchContentType.Contains(ProfilePicture.ContentType) || ProfilePicture.ContentLength > 80000) { ViewBag.ErrorMessage = "You need to use the following image extensions: png, jpg, gif"; return(View("Login")); } //We can't save the file before to save the member in the database //Check if data annotations are respected ==> See the RegisterModel Class if (!ModelState.IsValid) { //I want to get all error on the model like wrong email format, wrong password repetiton,.... foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { //add the error message into a viewbag to display on the view ViewBag.ErrorMessage += error.ErrorMessage + "<br>"; } } } else { ZookeeperRepository Zr = new ZookeeperRepository(ConfigurationManager.ConnectionStrings["CnstrDev"].ConnectionString); //I have to call the Insert function from ZookeeperRepository //If the insert succeeds, we get a complete Zookeeper with id value (calculated by the database) //If the insert failed, we receive a null value //We have to convert the registerModel(viewmodel) to a ZookeeperModel(Dal) before to call the function // this is why we call the static function RegisterToMembre from the Static class MapToDBModel Zookeeper ZM = Zr.Insert(MapToDBModel.RegisterToZookeeper(Rm)); if (M != null) { //Now I can save the picture //1 - Get the filename and extract the extension string[] splitFileName = ProfilePicture.FileName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); string ext = splitFileName[splitFileName.Length - 1]; //Get the last collumn of the array which contains the extension of the picture //2- Generate the new file name string newFileName = M.Id + "." + ext; //3- Save the picture //3.1 - Get the physic path of the photos folder string folderpath = Server.MapPath("~/photos/"); //3.2 - Combine folder path and new filename string FileNameToSave = folderpath + "/" + newFileName; //3.3 - Save try { //SaveAs is a procedure and not a function thus we have to surround with try catch to // get error if the SaveAs failed ProfilePicture.SaveAs(FileNameToSave); } catch (Exception) { ViewBag.ErrorMessage = "L'image n'a pas pu être sauvée"; throw; } //I want to pre-fill the login html input if the register succeed. //Thus , I use ViewBag to store the Email and a success message to communicate with the guest ViewBag.Login = Rm.Email; ViewBag.SuccessMessage = "Vous pouvez vous connecter"; } else { //If there is an issuer, I want to dispay a message on the view. //Thus I use Viewbag to send the message to the view ViewBag.ErrorMessage = "Erreur lors de l'insertion"; } } return(View("Login")); }
public ActionResult UpdateAnimal(AnimalModel toUpdate, HttpPostedFileBase Photo) { if (!ModelState.IsValid) { foreach (ModelState each_modelState in ViewData.ModelState.Values) { foreach (ModelError each_error in each_modelState.Errors) { ViewBag.ErrorMessage += each_error.ErrorMessage + "<br>"; } } return RedirectToAction("Index"); } else { AnimalRepository aniRepo = new AnimalRepository(ConfigurationManager.ConnectionStrings["My_Asptest_Cnstr"].ConnectionString); // 1. update reussi ? bool updatePart1OK = aniRepo.update(MapToDBModel.animalModelToAnimal(toUpdate)); // 2. photo : if (updatePart1OK) { if (Photo == null) { return View(ViewBag.Message = "Picture null, insersion failed"); } else { List<string> listeMIME = new List<string>() { "image/jpeg", "image/png", "image/gif" }; if (!listeMIME.Contains(Photo.ContentType) /*|| photoAnim.ContentLength > 800000*/) { ViewBag.ErrorMessage = "unauthorized extention (choose : png, jpg or gif)"; return View("Index"); } string[] splitPhotoname = Photo.FileName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); string ext = splitPhotoname[splitPhotoname.Length - 1]; string photoNew = toUpdate.IdAnimal + "animal" + "." + ext; toUpdate.Photo = photoNew; // saved in DB via mapper string chemin = Server.MapPath("~/photos/animal"); string photoToSave = chemin + "/" + photoNew; Photo.SaveAs(photoToSave); // try catch bool updatePart2OK = aniRepo.update(MapToDBModel.animalModelToAnimal(toUpdate)); // //if (updatePart2OK) //{ return RedirectToAction("Index", new { controller = "Home", area = "Admin" }); //} } } else { return View(ViewBag.Message = "Insersion failed"); } } }
public ActionResult Login(LoginModel lm) { UtilisateurRepository ur = new UtilisateurRepository(ConfigurationManager.ConnectionStrings["My_Asptest_Cnstr"].ConnectionString); if (!ModelState.IsValid) { foreach (ModelState each_modelState in ViewData.ModelState.Values) { foreach (ModelError each_error in each_modelState.Errors) { ViewBag.ErrorMessage += each_error.ErrorMessage + "<br>"; } } return(RedirectToAction("Index")); } else { ProfileModel pm = mapToVIEWmodels.utilisateurTOprofileModel(ur.verifLogin(MapToDBModel.loginToUtilisateur(lm))); if (pm != null) { SessionUtilisateur.ConnectedUser = pm; SessionUtilisateur.IsConnected = true; return(RedirectToAction("Index")); } else { ViewBag.ErrorInLoginProcess = "Error with tne email or password"; return(RedirectToAction("Index", new { Controller = "Home", Area = "" })); } //if ou else : faut passer par index de ce controller : pour suite des verif (parrain...) } }
public ActionResult Register(RegisterModelPOST rmPost, HttpPostedFileBase Photo) { UtilisateurRepository ur = new UtilisateurRepository(ConfigurationManager.ConnectionStrings["My_Asptest_Cnstr"].ConnectionString); if (!ModelState.IsValid) { foreach (ModelState each_modelState in ViewData.ModelState.Values) { foreach (ModelError each_error in each_modelState.Errors) { ViewBag.ErrorMessage += each_error.ErrorMessage + "<br>"; } } return(RedirectToAction("Index", new { controller = "Home", area = "" })); } else { //is admin or not ? VerifAdminModel verifAdmin = new VerifAdminModel(); if (rmPost.IsAdmin == verifAdmin.Code) // long string { verifAdmin.IsAdmin = true; } else if (rmPost.IsAdmin == null || rmPost.IsAdmin != verifAdmin.Code) { ViewBag.Message = "Not a administrator"; } rmPost.IsAdmin = verifAdmin.IsAdmin.ToString(); // 1. Ajouter MMembre sans photo ProfileModel pm = mapToVIEWmodels.utilisateurTOprofileModel(ur.insert(MapToDBModel.registerToUtilisateur(rmPost))); // 2. photo : if (pm == null) { ViewBag.Message = "The profileModel is Null"; return(RedirectToAction("Index", new { controller = "Home", area = "" })); } else //if (pm != null) { List <string> listeMIME = new List <string>() { "image/jpeg", "image/png", "image/gif" }; if (!listeMIME.Contains(Photo.ContentType) || Photo.ContentLength > 80000) { ViewBag.ErrorMessage = "Votre photo ne possède pas une extension autorisée (choisissez parmis : png, jpg, gif)"; return(View("Index")); } string[] splitPhotoname = Photo.FileName.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries); string ext = splitPhotoname[splitPhotoname.Length - 1]; string photoNew = pm.IdUtilisateur + "." + ext; // <== save in DB string chemin = Server.MapPath("~/photos/utilisateur"); string photoToSave = chemin + "/" + photoNew; Photo.SaveAs(photoToSave); pm.Photo = photoNew; // saved in DB via mapper // try catch bool reussi = ur.update(MapToDBModel.profileTOUtilisateur(pm)); // if (!reussi) { ViewBag.Message = "The profileModel updating failed (no picture)"; return(RedirectToAction("Index", new { controller = "Home", area = "" })); } else // reussi { if (!pm.IsAdmin) { if (pm.IdRole == 0) { return(RedirectToAction("Index", new { controller = "Home", area = "Parrain" })); } else { return(RedirectToAction("Index", new { controller = "Home", area = "Personnel" })); } } else // is admin { return(RedirectToAction("Index", new { controller = "Home", area = "Admin" })); } } } } }