public ActionResult Create([Bind(Include = "DateNaissance,NumTel,Nom,Prenom")] AdherentViewModel adherentViewModel) { string user = User.Identity.GetUserId(); if (db.Adherents.Any(a => a.Id == user)) { return(RedirectToAction("Details")); } if (ModelState.IsValid) { Adherent adherent = new Adherent { Id = User.Identity.GetUserId(), DateNaissance = adherentViewModel.DateNaissance, Prenom = adherentViewModel.Prenom, Nom = adherentViewModel.Nom, NumTel = adherentViewModel.NumTel, ResteaPayer = 0 }; db.Adherents.Add(adherent); db.SaveChanges(); return(RedirectToAction("Details")); } return(View(adherentViewModel)); }
public static void UpdateAdherent(ApplicationDbContext context, AdherentViewModel vmAdherent, IFormFile uploadFile) { ApplicationUser appUser = context.Users.First(x => x.Email == vmAdherent.OriginalEmail); appUser.Email = vmAdherent.Adherent.Email; vmAdherent.Adherent.Name = vmAdherent.Adherent.Name.ToUpper(); context.Update(appUser); context.Update(vmAdherent.Adherent); context.SaveChanges(); }
public IActionResult Edit(AdherentViewModel vmAdherent, IFormFile uploadFile) { if (ModelState.IsValid) { UploadAndSetAvatar(vmAdherent.Adherent, uploadFile); AdherentsBaseController.UpdateAdherent(_context, vmAdherent, uploadFile); return(RedirectToAction("Index")); } return(View(vmAdherent)); }
public IActionResult EditAdherent(AdherentViewModel vmAdherent, string uploadAvatar) { if (Authorized(Role.Volunteer) || vmAdherent.Adherent.Id == GetActiveAdherentStolon().AdherentId) { if (ModelState.IsValid) { UpdateAdherent(vmAdherent, uploadAvatar); return(RedirectToAction("Index")); } return(View(vmAdherent)); } return(Unauthorized()); }
public IActionResult EditAdherent(AdherentViewModel vmAdherent, IFormFile uploadFile) { if (!Authorized(Role.Volunteer)) { return(Unauthorized()); } if (ModelState.IsValid) { UploadAndSetAvatar(vmAdherent.Adherent, uploadFile); UpdateAdherent(_context, vmAdherent, uploadFile); return(RedirectToAction("Index")); } return(View(vmAdherent)); }
public IActionResult ChangeProducerInformations(AdherentViewModel vmAdherent, IFormFile uploadFile) { if (ModelState.IsValid) { UploadAndSetAvatar(vmAdherent.Adherent, uploadFile); ApplicationUser appUser = _context.Users.First(x => x.Email == vmAdherent.OriginalEmail); appUser.Email = vmAdherent.Adherent.Email; _context.Update(appUser); _context.Update(vmAdherent.Adherent); _context.SaveChanges(); return(RedirectToAction("Index")); } return(View(vmAdherent)); }
public ActionResult Edit([Bind(Include = "DateNaissance,NumTel,Nom,Prenom")] AdherentViewModel adherentViewModel) { if (ModelState.IsValid) { Adherent ad = db.Adherents.Find(User.Identity.GetUserId()); ad.DateNaissance = adherentViewModel.DateNaissance; ad.Prenom = adherentViewModel.Prenom; ad.Nom = adherentViewModel.Nom; ad.NumTel = adherentViewModel.NumTel; db.Entry(ad).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(RedirectToAction("Details")); }
public void UpdateAdherent(AdherentViewModel vmAdherent, string uploadAvatar) { ApplicationUser appUser = _context.Users.First(x => x.Email == vmAdherent.OriginalEmail); appUser.Email = vmAdherent.Adherent.Email; _context.Update(appUser); _context.SaveChanges(); _environment.DeleteFile(vmAdherent.Adherent.AvatarFilePath); vmAdherent.Adherent.AvatarFileName = _environment.UploadBase64Image(uploadAvatar, Configurations.AvatarStockagePath); Adherent adherent = _context.Adherents.FirstOrDefault(x => x.Id == vmAdherent.Adherent.Id); adherent.CloneAllPropertiesFrom(vmAdherent.Adherent); _context.Update(adherent); _context.SaveChanges(); }
public virtual async Task <IActionResult> Create(AdherentEdition edition, AdherentViewModel vmAdherent, IFormFile uploadFile) { if (!Authorized(Role.Volunteer)) { return(Unauthorized()); } if (ModelState.IsValid) { Stolon stolon = _context.Stolons.FirstOrDefault(x => x.Id == vmAdherent.Stolon.Id); #region Creating Consumer //Setting value for creation UploadAndSetAvatar(vmAdherent.Adherent, uploadFile); vmAdherent.Adherent.Name = vmAdherent.Adherent.Name.ToUpper(); AdherentStolon adherentStolon = new AdherentStolon(vmAdherent.Adherent, stolon, true); adherentStolon.RegistrationDate = DateTime.Now; adherentStolon.LocalId = _context.AdherentStolons.Where(x => x.StolonId == stolon.Id).Max(x => x.LocalId) + 1; adherentStolon.IsProducer = edition == AdherentEdition.Producer; _context.Adherents.Add(vmAdherent.Adherent); _context.AdherentStolons.Add(adherentStolon); #endregion Creating Consumer #region Creating linked application data var appUser = new ApplicationUser { UserName = vmAdherent.Adherent.Email, Email = vmAdherent.Adherent.Email }; appUser.User = vmAdherent.Adherent; var result = await _userManager.CreateAsync(appUser, vmAdherent.Adherent.Email); #endregion Creating linked application data // // _context.SaveChanges(); //Send confirmation mail string confirmationViewName = edition == AdherentEdition.Consumer ? "AdherentConfirmationMail" : "ProducerConfirmationMail"; Services.AuthMessageSender.SendEmail(stolon.Label, vmAdherent.Adherent.Email, vmAdherent.Adherent.Name, "Creation de votre compte", base.RenderPartialViewToString(confirmationViewName, adherentStolon)); return(RedirectToAction("Index")); } return(View(vmAdherent)); }
// GET: Adherents/Edit/5 public ActionResult Edit() { if (User.Identity.GetUserId() == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Adherent adherent = db.Adherents.Find(User.Identity.GetUserId()); if (adherent == null) { return(HttpNotFound()); } AdherentViewModel ad = new AdherentViewModel { Nom = adherent.Nom, Prenom = adherent.Prenom, DateNaissance = adherent.DateNaissance, NumTel = adherent.NumTel }; return(View(ad)); }