public ActionResult Creation(DossierView dossierView) { bool StatusCreation = false; string MessageCreation = string.Empty; //Send DropDowns Bags for Produits and Boites List <Produit> ListeProduits = dbContext.Produits.ToList(); List <Boite> ListeBoites = dbContext.Boites.ToList(); ViewBag.ListeProduits = new SelectList(ListeProduits, "idProduit", "nomProduit"); ViewBag.ListeBoites = new SelectList(ListeBoites, "idBoite", "codeBoite"); if (ModelState.IsValid) { //Get Custom Current User ID HttpCookie authCookie = Request.Cookies["Cookie1"]; FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); var serializeModel = JsonConvert.DeserializeObject <CustomSerializeModel>(authTicket.UserData); CustomPrincipal principal = new CustomPrincipal(authTicket.Name); principal.idUser = serializeModel.idUser; //Ajout d'un Dossier var dossier = new Dossier() { idUser = principal.idUser, idProduit = dossierView.idProduit, idBoite = dossierView.idBoite, codeDossier = dossierView.codeDossier, dateCreation = dossierView.dateCreation, dureeLegale = dossierView.dureeLegale, dureeConv = dossierView.dureeConv }; dbContext.Dossiers.Add(dossier); dbContext.SaveChanges(); StatusCreation = true; } else { MessageCreation = "Veuillez vérifier les données insérées"; } ViewBag.Message = MessageCreation; ViewBag.Status = StatusCreation; return(View(dossierView)); }
public ActionResult Registration(RegistrationView registrationView) { //List<Branche> ListeBranche = dbContext.Branches.ToList(); //List<Role> ListeRole = dbContext.Roles.ToList(); //ViewBag.ListeBranche = new SelectList(ListeBranche, "idBranche", "codeBranche"); //ViewBag.ListeRole = new SelectList(ListeRole, "idRole", "nomRole"); bool statusRegistration = false; string messageRegistration = string.Empty; if (ModelState.IsValid) { // Matricule Verification try { MembershipUser UserNameByMatricule = Membership.GetUser(registrationView.matriculeUser); if (UserNameByMatricule != null) { messageRegistration = "Cette Matricule existe déjà"; ViewBag.Message = messageRegistration; return(View(registrationView)); } } catch (Exception ex) { throw ex; } //Save User Data var user = new Utilisateur() { matriculeUser = registrationView.matriculeUser, idBranche = registrationView.idBranche, Roles = dbContext.Roles.Where(x => x.idRole == registrationView.role).ToList(), nomUser = registrationView.nomUser, prenomUser = registrationView.prenomUser, mdpUser = HashPassword(registrationView.Password), emailUser = registrationView.emailUser, adresseUser = registrationView.adresseUser, sexeUser = registrationView.sexeUser, cinUser = registrationView.cinUser, rememberMeUser = true, isActiveUser = true }; dbContext.Utilisateurs.Add(user); dbContext.SaveChanges(); statusRegistration = true; } else { List <Branche> ListeBranche = dbContext.Branches.ToList(); List <Role> ListeRole = dbContext.Roles.ToList(); ViewBag.ListeBranche = new SelectList(ListeBranche, "idBranche", "codeBranche"); ViewBag.Role = new SelectList(dbContext.Roles, "idRole", "nomRole"); messageRegistration = "Veuillez vérifier les données insérées"; } ViewBag.Message = messageRegistration; ViewBag.Status = statusRegistration; return(View(registrationView)); }
public ActionResult AddOrEditDossier(Dossier dossier) { List <Produit> ListeProduits = dbContext.Produits.ToList(); List <Boite> ListeBoites = dbContext.Boites.ToList(); ViewBag.ListeProduits = new SelectList(ListeProduits, "idProduit", "nomProduit"); ViewBag.ListeBoites = new SelectList(ListeBoites, "idBoite", "codeBoite"); if (dossier.idDossier == 0) { dbContext.Configuration.ProxyCreationEnabled = false; string query = "SELECT * FROM Dossier WHERE codeDossier = @p0"; var dossiers = dbContext.Dossiers.SqlQuery(query, dossier.codeDossier).ToList(); int count = dossiers.Count(); if (count == 0) { dbContext.Dossiers.Add(dossier); dbContext.SaveChanges(); return(Json(new { success = true, message = "Ajout : Succés" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = "Ce dossier existe déjà" }, JsonRequestBehavior.AllowGet)); } } else { dbContext.Configuration.ProxyCreationEnabled = false; dbContext.Entry(dossier).State = EntityState.Modified; dbContext.SaveChanges(); return(Json(new { success = true, message = "Mise à jour : Succés" }, JsonRequestBehavior.AllowGet)); } }