public async Task <IActionResult> Create([Bind("ID,Prenom,Nom,Mail,GSM")] Representant representant) { if (ModelState.IsValid) { _context.Add(representant); var tableauFournisseur = Request.Form["Fournisseur"]; List <int> ListeFournisseur = new List <int>(); foreach (var mot in tableauFournisseur) { ListeFournisseur.Add(int.Parse(mot)); } foreach (int Fournisseur in ListeFournisseur) { Contact contact = new Contact(); contact.RepresentantID = representant.ID; contact.FournisseurID = Fournisseur; _context.Add(contact); await _context.SaveChangesAsync(); } await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(representant)); }
public async Task <IActionResult> Edit(int id, [Bind("ID,Prenom,Nom,Mail,GSM")] Representant representant) { if (id != representant.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(representant); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RepresentantExists(representant.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(representant)); }
public ActionResult Index(RepresentantViewModel viewModel, string returnUrl) { int idElement = 0; if (Request.Form["btn-login"] != null) { if (ModelState.IsValid) { Representant representant = dal.Authentifier(viewModel.Representant.Courriel, viewModel.Representant.MotDePasse); if (representant != null) { Session["representant"] = representant; FormsAuthentication.SetAuthCookie(representant.Id.ToString(), false); if (!string.IsNullOrWhiteSpace(returnUrl) && Url.IsLocalUrl(returnUrl)) { return(Redirect(returnUrl)); } ElementListe element = new ElementListe(); idElement = dal.ajouterElement(element); List <ElementListe> Liste = dal.ObtenirElements(); return(RedirectToAction("Tableau", "Accueil")); } ModelState.AddModelError("Utilisateur.Courriel", "Compte inexistant."); } return(View("~/Views/Accueil/Index.cshtml", viewModel)); } else if (Request.Form["btnCreer"] != null) { CreerCompte(viewModel.Representant); } return(View("~/Views/Accueil/Index.cshtml", viewModel)); }
//Ajouter representant static public bool ajouterRepresentant(Representant representant) { bool cree = false; RequeteEntreprise.ajouterRepresentant(representant); return(cree); }
public bool CreerCompte(Representant utilisateur) { if (ModelState.IsValid) { if (!dal.VerifierExistanceRepresentant(utilisateur.Courriel)) { int id = dal.AjouterRepresentant(utilisateur.Courriel, utilisateur.MotDePasse); FormsAuthentication.SetAuthCookie(id.ToString(), false); return(true); } ModelState.AddModelError("UserExistant", "L'utilisateur est déja existant"); } return(false); }
public AjouterRepresentant(Utilisateur user, int idEntreprise) { InitializeComponent(); MonRepresentant = new Representant(); MonRepresentant.IdEntreprise = idEntreprise; IsModified = false; User = user; List <string> listLangue; listLangue = new List <string>(); foreach (Langue id in ListeDescription.listLangue) { listLangue.Add(id.Description); } langueVue.ItemsSource = listLangue; }
//Modifier representant public static bool modifierRepresentant(Representant representant) { bool modifie = false; string requete = @"UPDATE representant SET prenom=@prenom, nom=@nom, courriel=@courriel, tel1=@tel1, tel2=@tel2, tel3=@tel3, departement=@departement, poste=@poste, idEntreprise=@idEntreprise, idLangue=@idLangue, idUtilisateur=@idUtilisateur WHERE id=@id"; SqlParameter id = new SqlParameter("@id", representant.Id); SqlParameter prenom = new SqlParameter("@prenom", !string.IsNullOrEmpty(representant.Prenom) ? representant.Prenom : (object)DBNull.Value); SqlParameter nom = new SqlParameter("@nom", !string.IsNullOrEmpty(representant.Nom) ? representant.Nom : (object)DBNull.Value); SqlParameter courriel = new SqlParameter("@courriel", !string.IsNullOrEmpty(representant.Courriel) ? representant.Courriel : (object)DBNull.Value); SqlParameter tel1 = new SqlParameter("@tel1", !string.IsNullOrEmpty(representant.Telephone1) ? representant.Telephone1 : (object)DBNull.Value); SqlParameter tel2 = new SqlParameter("@tel2", !string.IsNullOrEmpty(representant.Telephone2) ? representant.Telephone2 : (object)DBNull.Value); SqlParameter tel3 = new SqlParameter("@tel3", !string.IsNullOrEmpty(representant.Telephone3) ? representant.Telephone3 : (object)DBNull.Value); SqlParameter departement = new SqlParameter("@departement", !string.IsNullOrEmpty(representant.Departement) ? representant.Departement : (object)DBNull.Value); SqlParameter poste = new SqlParameter("@poste", !string.IsNullOrEmpty(representant.Poste) ? representant.Poste : (object)DBNull.Value); SqlParameter idEntreprise = new SqlParameter("@idEntreprise", representant.IdEntreprise); SqlParameter idLangue = new SqlParameter("@idLangue", representant.IdLangue != null ? representant.IdLangue : (object)DBNull.Value); SqlParameter idUtilisateur = new SqlParameter("@idUtilisateur", representant.Modification.UtilisateurId); using (SqlConnection conn = new SqlConnection(ConnectionString)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(requete, conn)) { cmd.CommandType = CommandType.Text; cmd.Parameters.Add(id); cmd.Parameters.Add(prenom); cmd.Parameters.Add(nom); cmd.Parameters.Add(courriel); cmd.Parameters.Add(tel1); cmd.Parameters.Add(tel2); cmd.Parameters.Add(tel3); cmd.Parameters.Add(departement); cmd.Parameters.Add(poste); cmd.Parameters.Add(idEntreprise); cmd.Parameters.Add(idLangue); cmd.Parameters.Add(idUtilisateur); int affectes = (int)cmd.ExecuteNonQuery(); if (affectes != 0) { modifie = true; } } } return(modifie); }
//Ajouter representant public static bool ajouterRepresentant(Representant representant) { bool cree = false; string requete = @"INSERT INTO representant (prenom, nom, courriel, tel1, tel2, tel3, departement, poste, idEntreprise, idLangue, idUtilisateur) OUTPUT INSERTED.id VALUES (@prenom, @nom, @courriel, @tel1, @tel2, @tel3, @departement, @poste, @idEntreprise, @idLangue, @idUtilisateur)"; SqlParameter prenom = new SqlParameter("@prenom", !string.IsNullOrEmpty(representant.Prenom) ? representant.Prenom : (object)DBNull.Value); SqlParameter nom = new SqlParameter("@nom", !string.IsNullOrEmpty(representant.Nom) ? representant.Nom : (object)DBNull.Value); SqlParameter courriel = new SqlParameter("@courriel", !string.IsNullOrEmpty(representant.Courriel) ? representant.Courriel : (object)DBNull.Value); SqlParameter tel1 = new SqlParameter("@tel1", !string.IsNullOrEmpty(representant.Telephone1) ? representant.Telephone1 : (object)DBNull.Value); SqlParameter tel2 = new SqlParameter("@tel2", !string.IsNullOrEmpty(representant.Telephone2) ? representant.Telephone2 : (object)DBNull.Value); SqlParameter tel3 = new SqlParameter("@tel3", !string.IsNullOrEmpty(representant.Telephone3) ? representant.Telephone3 : (object)DBNull.Value); SqlParameter departement = new SqlParameter("@departement", !string.IsNullOrEmpty(representant.Departement) ? representant.Departement : (object)DBNull.Value); SqlParameter poste = new SqlParameter("@poste", !string.IsNullOrEmpty(representant.Poste) ? representant.Poste : (object)DBNull.Value); SqlParameter idEntreprise = new SqlParameter("@idEntreprise", representant.IdEntreprise); SqlParameter idLangue = new SqlParameter("@idLangue", representant.IdLangue != null ? representant.IdLangue : (object)DBNull.Value); SqlParameter idUtilisateur = new SqlParameter("@idUtilisateur", representant.Modification.UtilisateurId); using (SqlConnection conn = new SqlConnection(ConnectionString)) { conn.Open(); using (SqlCommand cmd = new SqlCommand(requete, conn)) { cmd.CommandType = CommandType.Text; cmd.Parameters.Add(prenom); cmd.Parameters.Add(nom); cmd.Parameters.Add(courriel); cmd.Parameters.Add(tel1); cmd.Parameters.Add(tel2); cmd.Parameters.Add(tel3); cmd.Parameters.Add(departement); cmd.Parameters.Add(poste); cmd.Parameters.Add(idEntreprise); cmd.Parameters.Add(idLangue); cmd.Parameters.Add(idUtilisateur); representant.Id = (Int32)cmd.ExecuteScalar(); if (representant.Id > 0) { cree = true; } } } return(cree); }
private bool EnvoyerCourriel(string message) { if (!string.IsNullOrEmpty(message)) { if (Session["representant"] != null) { Representant rep = Session["representant"] as Representant; if (utilitaires.EnvoyerCourriel("Demande du support", message, rep)) { return(true); } else { ModelState.AddModelError("courrielerreur", "Il y a eu une erreur lors de l'envoit du courriel."); return(false); } } } return(false); }
//Modifier Representant static public bool modifierRepresentant(Representant representant) { return(RequeteEntreprise.modifierRepresentant(representant)); }
protected void btnSave_Click(object sender, EventArgs e) { representant = new Representant(); manager = new RepresentantManager(this); // // Clone the original representant for the linq track changes // if (Page.ViewState["RepresentantId"] != null) { original_representant = manager.GetRepresentant(Convert.ToInt32(Page.ViewState["RepresentantId"])); representant.CopyPropertiesFrom(original_representant); } representant.ModifiedDate = DateTime.Now; representant.CompanyId = Company.CompanyId; // //fill fields of account // if (!String.IsNullOrEmpty(cboBank.SelectedValue)) representant.BankId = Convert.ToInt32(cboBank.SelectedValue); else representant.BankId = null; if (!String.IsNullOrEmpty(txtAccountNumber.Text)) representant.AccountNumber = txtAccountNumber.Text; else representant.AccountNumber = null; if (!String.IsNullOrEmpty(txtAgency.Text)) representant.Agency = txtAgency.Text; else representant.Agency = null; // //fill rating value // representant.Rating = rtnRating.CurrentRating; if (Profile1.ProfileEntity != null) { representant.ProfileId = Profile1.ProfileEntity.ProfileId; if (representant.ProfileId == 0) representant.Profile = Profile1.ProfileEntity; } else { representant.LegalEntityProfileId = Profile1.CompanyProfileEntity.LegalEntityProfileId; if (representant.LegalEntityProfileId == 0) representant.LegalEntityProfile = Profile1.CompanyProfileEntity; } if (Page.ViewState["RepresentantId"] == null && Page.ViewState["ProfileExists"] != "0") manager.Insert(representant); else manager.update(original_representant, representant); if (!String.IsNullOrEmpty(Request["RepresentantId"])) Response.Redirect("Representants.aspx"); else Response.Redirect("Representant.aspx?RepresentantId=" + representant.RepresentantId); }
/// <summary> /// this method inserts a representant /// </summary> /// <param name="entity"></param> public void Insert(Representant entity) { DbContext.Representants.InsertOnSubmit(entity); DbContext.SubmitChanges(); }
/// <summary> /// this method updates a Representant /// </summary> /// <param name="original_entity"></param> /// <param name="entity"></param> public void update(Representant original_entity, Representant entity) { original_entity.CopyPropertiesFrom(entity); DbContext.SubmitChanges(); }
public RepresentantAdaptateur() { Representant = new Representant(); ListAdresse = new List <Adresse>(); }
/// <summary> /// this method delete Representant /// </summary> /// <param name="entity"></param> public void Delete(Representant entity) { //DbContext.Representants.Attach(entity); DbContext.Representants.DeleteOnSubmit(entity); DbContext.SubmitChanges(); }
//Recuperer liste representant d'un entreprise public static List <Representant> recupererRepresentantsEntreprise(int idEntreprise) { List <Representant> listeRepresentants = null; SqlParameter idEntrepriseParam = new SqlParameter("@idEntreprise", idEntreprise); using (SqlConnection conn = new SqlConnection(ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.Parameters.Add(idEntrepriseParam); cmd.CommandText = @"select * from representant where idEntreprise=@idEntreprise and actif=1"; using (SqlDataReader rdr = cmd.ExecuteReader()) { if (rdr.HasRows) { listeRepresentants = new List <Representant>(); while (rdr.Read()) { Representant representant = new Representant(); representant.Id = (int)rdr["id"]; if (!(rdr["prenom"] == DBNull.Value)) { representant.Prenom = rdr["prenom"].ToString(); } if (!(rdr["nom"] == DBNull.Value)) { representant.Nom = rdr["nom"].ToString(); } if (!(rdr["courriel"] == DBNull.Value)) { representant.Courriel = rdr["courriel"].ToString(); } if (!(rdr["tel1"] == DBNull.Value)) { representant.Telephone1 = rdr["tel1"].ToString(); } if (!(rdr["tel2"] == DBNull.Value)) { representant.Telephone2 = rdr["tel2"].ToString(); } if (!(rdr["tel3"] == DBNull.Value)) { representant.Telephone3 = rdr["tel3"].ToString(); } if (!(rdr["departement"] == DBNull.Value)) { representant.Departement = rdr["departement"].ToString(); } if (!(rdr["poste"] == DBNull.Value)) { representant.Poste = rdr["poste"].ToString(); } representant.IdEntreprise = (int)rdr["idEntreprise"]; if (!(rdr["idLangue"] == DBNull.Value)) { representant.IdLangue = (int)rdr["idLangue"]; } else { representant.IdLangue = null; } representant.Actif = (bool)rdr["actif"]; representant.Modification = new Modification(); representant.Modification.UtilisateurId = (int)rdr["idUtilisateur"]; representant.Modification.DateModification = Convert.ToDateTime(rdr["dateModification"]); listeRepresentants.Add(representant); } } } } } return(listeRepresentants); }
public static Representant recupererRepresentantParId(int idRepresentant) { Representant representant = null; SqlParameter idRepresentantParam = new SqlParameter("@idRepresentant", idRepresentant); using (SqlConnection conn = new SqlConnection(ConnectionString)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) { cmd.Parameters.Add(idRepresentantParam); cmd.CommandText = @"SELECT * FROM representant WHERE id=@idRepresentant AND actif=1"; using (SqlDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { representant = new Representant(); representant.Modification = new Modification(); //remplir l'objet entreprise representant.Id = (int)rdr["id"]; if (!(rdr["prenom"] == DBNull.Value)) { representant.Prenom = rdr["prenom"].ToString(); } if (!(rdr["nom"] == DBNull.Value)) { representant.Nom = rdr["nom"].ToString(); } if (!(rdr["courriel"] == DBNull.Value)) { representant.Courriel = rdr["courriel"].ToString(); } if (!(rdr["tel1"] == DBNull.Value)) { representant.Telephone1 = rdr["tel1"].ToString(); } if (!(rdr["tel2"] == DBNull.Value)) { representant.Telephone2 = rdr["tel2"].ToString(); } if (!(rdr["tel3"] == DBNull.Value)) { representant.Telephone3 = rdr["tel3"].ToString(); } if (!(rdr["departement"] == DBNull.Value)) { representant.Departement = rdr["departement"].ToString(); } if (!(rdr["poste"] == DBNull.Value)) { representant.Poste = rdr["poste"].ToString(); } representant.IdEntreprise = (int)rdr["idEntreprise"]; if (!(rdr["idLangue"] == DBNull.Value)) { representant.IdLangue = (int)rdr["idLangue"]; } else { representant.IdLangue = null; } representant.Actif = (bool)rdr["actif"]; representant.Modification.UtilisateurId = (int)rdr["idUtilisateur"]; representant.Modification.DateModification = Convert.ToDateTime(rdr["dateModification"]); } } } } return(representant); }
protected void Page_Load(object sender, EventArgs e) { manager = new RepresentantManager(this); //retrieve the RepresentantId from Modal Popup if (!String.IsNullOrEmpty(Request["RepresentantId"])) { Page.ViewState["RepresentantId"] = Request["RepresentantId"]; lblRepresentantCode.Visible = true; lblRepresentantCode.Text = "Código do Representante: " + Request["RepresentantId"]; } if (Context.Items["RepresentantId"] != null) Page.ViewState["RepresentantId"] = Context.Items["RepresentantId"]; if (Page.ViewState["RepresentantId"] != null) { original_representant = manager.GetRepresentant(Convert.ToInt32(Page.ViewState["RepresentantId"])); if (!IsPostBack && original_representant != null) { /* * The code below checks the type of profile(LegalEntityProfile/Profile) */ if (original_representant.LegalEntityProfile != null) Profile1.CompanyProfileEntity = original_representant.LegalEntityProfile; else Profile1.ProfileEntity = original_representant.Profile; // //load bank informations // if (original_representant.BankId.HasValue) cboBank.SelectedValue = Convert.ToString(original_representant.BankId); txtAccountNumber.Text = original_representant.AccountNumber; txtAgency.Text = original_representant.Agency; // //load ranking value // if (original_representant.Rating != null) rtnRating.CurrentRating = Convert.ToInt32(original_representant.Rating); } } else { // // Legal Entity // if (Page.ViewState["LegalEntityProfileId"] != null) { original_representant = manager.GetRepresentantByLegalEntityProfile(Company.CompanyId, Convert.ToInt32(Page.ViewState["LegalEntityProfileId"])); if (original_representant != null) { Page.ViewState["ProfileExists"] = "0"; /* * if isn't a postback set the values of company in profile_LegalEntity1 * else the values are reload in all postback * */ if (!IsPostBack) Profile1.CompanyProfileEntity = original_representant.LegalEntityProfile; } } // // Natural Person // if (Page.ViewState["ProfileId"] != null) { original_representant = manager.GetRepresentantByProfile(Company.CompanyId, Convert.ToInt32(Page.ViewState["ProfileId"])); if (original_representant != null) { Page.ViewState["ProfileExists"] = "0"; /*if isn't a postback set the values of company in profile * else the values are reload in all postback */ if (!IsPostBack) Profile1.ProfileEntity = original_representant.Profile; } } if (original_representant != null) Page.ViewState["RepresentantId"] = original_representant.RepresentantId; } }
protected void btnSave_Click(object sender, EventArgs e) { representant = new Representant(); manager = new RepresentantManager(this); // // Clone the original representant for the linq track changes // if (Page.ViewState["RepresentantId"] != null) { original_representant = manager.GetRepresentant(Convert.ToInt32(Page.ViewState["RepresentantId"])); representant.CopyPropertiesFrom(original_representant); } representant.ModifiedDate = DateTime.Now; representant.CompanyId = Company.CompanyId; // //fill fields of account // if (!String.IsNullOrEmpty(cboBank.SelectedValue)) { representant.BankId = Convert.ToInt32(cboBank.SelectedValue); } else { representant.BankId = null; } if (!String.IsNullOrEmpty(txtAccountNumber.Text)) { representant.AccountNumber = txtAccountNumber.Text; } else { representant.AccountNumber = null; } if (!String.IsNullOrEmpty(txtAgency.Text)) { representant.Agency = txtAgency.Text; } else { representant.Agency = null; } // //fill rating value // representant.Rating = rtnRating.CurrentRating; if (Profile1.ProfileEntity != null) { representant.ProfileId = Profile1.ProfileEntity.ProfileId; if (representant.ProfileId == 0) { representant.Profile = Profile1.ProfileEntity; } } else { representant.LegalEntityProfileId = Profile1.CompanyProfileEntity.LegalEntityProfileId; if (representant.LegalEntityProfileId == 0) { representant.LegalEntityProfile = Profile1.CompanyProfileEntity; } } if (Page.ViewState["RepresentantId"] == null && Page.ViewState["ProfileExists"] != "0") { manager.Insert(representant); } else { manager.update(original_representant, representant); } if (!String.IsNullOrEmpty(Request["RepresentantId"])) { Response.Redirect("Representants.aspx"); } else { Response.Redirect("Representant.aspx?RepresentantId=" + representant.RepresentantId); } }
protected void Page_Load(object sender, EventArgs e) { manager = new RepresentantManager(this); //retrieve the RepresentantId from Modal Popup if (!String.IsNullOrEmpty(Request["RepresentantId"])) { Page.ViewState["RepresentantId"] = Request["RepresentantId"]; lblRepresentantCode.Visible = true; lblRepresentantCode.Text = "Código do Representante: " + Request["RepresentantId"]; } if (Context.Items["RepresentantId"] != null) { Page.ViewState["RepresentantId"] = Context.Items["RepresentantId"]; } if (Page.ViewState["RepresentantId"] != null) { original_representant = manager.GetRepresentant(Convert.ToInt32(Page.ViewState["RepresentantId"])); if (!IsPostBack && original_representant != null) { /* * The code below checks the type of profile(LegalEntityProfile/Profile) */ if (original_representant.LegalEntityProfile != null) { Profile1.CompanyProfileEntity = original_representant.LegalEntityProfile; } else { Profile1.ProfileEntity = original_representant.Profile; } // //load bank informations // if (original_representant.BankId.HasValue) { cboBank.SelectedValue = Convert.ToString(original_representant.BankId); } txtAccountNumber.Text = original_representant.AccountNumber; txtAgency.Text = original_representant.Agency; // //load ranking value // if (original_representant.Rating != null) { rtnRating.CurrentRating = Convert.ToInt32(original_representant.Rating); } } } else { // // Legal Entity // if (Page.ViewState["LegalEntityProfileId"] != null) { original_representant = manager.GetRepresentantByLegalEntityProfile(Company.CompanyId, Convert.ToInt32(Page.ViewState["LegalEntityProfileId"])); if (original_representant != null) { Page.ViewState["ProfileExists"] = "0"; /* * if isn't a postback set the values of company in profile_LegalEntity1 * else the values are reload in all postback * */ if (!IsPostBack) { Profile1.CompanyProfileEntity = original_representant.LegalEntityProfile; } } } // // Natural Person // if (Page.ViewState["ProfileId"] != null) { original_representant = manager.GetRepresentantByProfile(Company.CompanyId, Convert.ToInt32(Page.ViewState["ProfileId"])); if (original_representant != null) { Page.ViewState["ProfileExists"] = "0"; /*if isn't a postback set the values of company in profile * else the values are reload in all postback */ if (!IsPostBack) { Profile1.ProfileEntity = original_representant.Profile; } } } if (original_representant != null) { Page.ViewState["RepresentantId"] = original_representant.RepresentantId; } } }