// GET: User/Edit/5 public async Task <IActionResult> Edit(long id) { ProjetModel projet = await _projetService.GetAsync(HttpContext.Session, id); var lstUserByProjet = (await _projetService.GetListUserByProjectAsync(HttpContext.Session, projet.Id.GetValueOrDefault(0))).Select(s => new { Id = s.Id, Nom = s.Nom, Prenom = s.Prenom, Selected = true }).ToList(); CompteModel compte = _compteService.GetConnectedCompte(HttpContext.Session); List <UserModel> lstUser = await _userService.GetListUserByManagerAsync(HttpContext.Session, compte.User.Id.GetValueOrDefault(0)); var listUserTolal = lstUser.Where(w => lstUserByProjet == null || lstUserByProjet.Where(x => x.Id == w.Id).Count() == 0) .Select(s => new { Id = s.Id, Nom = s.Nom, Prenom = s.Prenom, Selected = false }).Concat(lstUserByProjet).ToList(); //for(int i = 0; i < listUserTolal.Count();i++) { } ViewBag.lstUser = listUserTolal ?? new[] { new { Id = (long?)0, Nom = "", Prenom = "", Selected = false } }.ToList(); ViewData.Model = projet; return(View()); }
public bool SaveProjet(ProjetModel pm) { //MAppers ProjetEntity pe = new ProjetEntity(); pe.Nom = pm.Nom; pe.Description = pm.Description; pe.Piece = pm.Piece; pe.Budget = pm.Budget; pe.DateDeDebut = DateTime.Now; pe.DateDeFin = DateTime.Now; pe.Image = pm.Image; int idProjet = 0; bool test = ((ProjetRepository)_projetRepo).InsertWithId(pe, out idProjet); if (test) { pm.IdProjet = idProjet; return(((StatutRepository)_statutRepository).InsertFromProject(pm.IdStatut, idProjet)); } else { return(false); } }
public ActionResult UploadPicture(ProjetModel um, HttpPostedFileBase FilePicture) { if (FilePicture.ContentLength > 0 && FilePicture.ContentLength < 20000) { //2 Vérifier le type string extension = Path.GetExtension(FilePicture.FileName); if (valideImageType.Contains(extension)) { //3 vérifier si le dossier de destination existe //D:\Cours\Wad20\NetFlask\images\Users\1 string destFolder = Path.Combine(Server.MapPath("~/images/portfolio"), SessionUtil.ConnectedProjet.IdProjet.ToString()); if (!Directory.Exists(destFolder)) { Directory.CreateDirectory(destFolder); } //4 - Upload de l'image FilePicture.SaveAs(Path.Combine(destFolder, FilePicture.FileName)); //5 Mise à jour de l'objet User SessionUtil.ConnectedProjet.Image = FilePicture.FileName; return(RedirectToAction("Index", "Home")); } } //Remarque : il faudra également sauvegarder dans la DB DataContext ctx = new DataContext(ConfigurationManager.ConnectionStrings["Cnstr"].ConnectionString); return(View(SessionUtil.ConnectedProjet)); }
public ActionResult Index(ProjetModel projet, HttpPostedFileBase FilePicture) { if (ModelState.IsValid) { if (FilePicture.ContentLength > 0 && FilePicture.ContentLength < 200000000) { //2 Vérifier le type string extension = Path.GetExtension(FilePicture.FileName); if (valideImageType.Contains(extension)) { //1- DB projet.Image = FilePicture.FileName; DataContext ctx = new DataContext(ConfigurationManager.ConnectionStrings["Cnstr"].ConnectionString); if (ctx.SaveProjet(projet)) { //3 vérifier si le dossier de destination existe //D:\Cours\Wad20\NetFlask\images\Users\1 string destFolder = Path.Combine(Server.MapPath("~/images/portfolio"), projet.IdProjet.ToString()); if (!Directory.Exists(destFolder)) { Directory.CreateDirectory(destFolder); } //4 - Upload de l'image FilePicture.SaveAs(Path.Combine(destFolder, FilePicture.FileName)); //5 Mise à jour de l'objet User SessionUtil.ConnectedProjet = projet; return(RedirectToAction("Realisations", "Home", new { area = "" })); } else { return(View()); } } else { return(View()); } } else { return(View()); } } else { return(View()); } }
public async Task <ActionResult> GetRubrique(ProjetModel projet) { try { List <RubriqueModel> LstRubrique = await _rubriqueService.GetListRubriqueByProjet(HttpContext.Session, projet.Id); return(Json(LstRubrique)); } catch (Exception e) { //return null; return(Json(new { someValue = "ko" })); } }
public ProjetModel GetOneProjet(ProjetEntity pe) { ProjetModel pm = new ProjetModel(); pm.Nom = pe.Nom; pm.Description = pe.Description; pm.Piece = pe.Piece; pm.Budget = pe.Budget; pm.DateDeDebut = DateTime.Now; pm.DateDeFin = DateTime.Now; pm.Image = pe.Image; return(pm); }
public async Task <IActionResult> AddProject([Bind("Titre", "DateCreation", "DateCloture")] ProjetModel projet, List <long> membres) { try { CompteModel compte = _compteService.GetConnectedCompte(HttpContext.Session); projet.createdBy = compte.User; ProjetModel prj = await _projetService.AddAsync(HttpContext.Session, projet); foreach (long item in membres) { await _projetService.AffecterUserToProjetAsync(HttpContext.Session, prj.Id, item); } return(RedirectToAction("List", "Projet")); } catch (Exception e) { //return null; return(View()); } }
public async Task <ActionResult> AddRbrique(List <RubriqueModel> rubriques, ProjetModel projet) { try { List <RubriqueModel> Lstrubriques = new List <RubriqueModel>(); Lstrubriques = rubriques; foreach (RubriqueModel item in Lstrubriques) { item.Projet = projet; RubriqueModel rubrique = await _rubriqueService.AddAsync(HttpContext.Session, item); } return(Json(new { someValue = "ok" })); } catch (Exception e) { //return null; return(Json(new { someValue = "ko" })); } }
public async Task <IActionResult> EditAsync(long id, ProjetModel projet, List <long> membres) { try { projet.Id = id; CompteModel compte = _compteService.GetConnectedCompte(HttpContext.Session); projet.createdBy = compte.User; await _projetService.UpdateAsync(HttpContext.Session, projet); await _projetService.RemoveAllUserFromProjetAsync(HttpContext.Session, projet.Id); foreach (long item in membres) { await _projetService.AffecterUserToProjetAsync(HttpContext.Session, projet.Id, item); } return(RedirectToAction("List", "Projet")); } catch (Exception e) { //return null; return(View()); } }