public ActionResult Ajout(string id)
 {
     try
     {
         Session["ID"] = null;
         InitAjoutView();
         ViewBag.IsCompleted = false;
         PisteurModel pist = new PisteurModel();
         if (!string.IsNullOrEmpty(id))
         {
             int _id = Convert.ToInt32(id);
             pist = DbFactory.FindPisteur(_id);
             Session["ID"] = pist.ID_AUTO;
         }
         pist.GetList();
         return View(pist);
     }
     catch (Exception ex)
     {
       string message = ex.Message;
         if (ex.InnerException != null)
         {
             message += ex.InnerException.Message;
         }
         message += ex.StackTrace;
         message += ex.GetType().ToString();
         Session["ErrorHandle"] = message;
         return Redirect("Account/GeneralFailure");
     }
 }
Beispiel #2
0
 public static PisteurModel FindPisteur(int id)
 {
     List<PISTEUR> _list = PISTEUR.GetList();
     PISTEUR item = _list.Find(c => c.ID_AUTO == id);
     //List<PISTEUR> _listPisteur = new List<PISTEUR>();
     PisteurModel _pisteur = new PisteurModel();
     if (item != null)
     {
         _pisteur.ID_AUTO = item.ID_AUTO;
         _pisteur.NOM = item.NOM;
         _pisteur.PRENOM = item.PRENOM;
         _pisteur.ID_ZONE = item.ID_ZONE;
         _pisteur.TEL = item.CONTACT;
         _pisteur.VILLAGE = item.VILLAGE;
         //_listMember.Add(_member);
     }
     return _pisteur;
 }
        public ActionResult Ajout(PisteurModel _pisteur, string returnUrl)
        {
            //if (Session["UserConnected"] == null) return Redirect("/LoginSk/_loginSkinned");
            PisteurModel pisteur;

            try
            {
                
                if (ModelState.IsValid)
                {
                    if (Session["ID"] != null) _pisteur.ID_AUTO = (int)Session["ID"];
                    //string userName = WebSecurity.CurrentUserName;
                    DbFactory.SavePisteur(_pisteur);
                    ViewBag.IsCompleted = true;
                    InitAjoutView();
                    ViewBag.IsCompleted = true;
                    ModelState.Clear();
                    pisteur = new PisteurModel();
                    pisteur.GetList();
                    return View(pisteur);
                }
                else
                {
                    InitAjoutView();
                    _pisteur.GetList();
                    return View(_pisteur);
                }

            }
            catch (Exception ex)
            {
                string message = ex.Message;
                if (ex.InnerException != null)
                {
                    message += ex.InnerException.Message;
                }
                message += ex.StackTrace;
                message += ex.GetType().ToString();
                Session["ErrorHandle"] = message;
                return Redirect("/LoginSk/GeneralFailure");
            }


        }
Beispiel #4
0
        public static void SavePisteur(PisteurModel model)
        {
            string instanceName = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            using (SqlConnection connPool = new SqlConnection(instanceName))
            {
                if (connPool.State == System.Data.ConnectionState.Closed)
                    connPool.Open();
                PISTEUR dataObj = new PISTEUR();

                dataObj.NOM = model.NOM;
                dataObj.PRENOM = model.PRENOM;
                dataObj.CONTACT = model.TEL;
                dataObj.ID_ZONE = model.ID_ZONE;
                dataObj.VILLAGE = model.VILLAGE;

                if (model.ID_AUTO != 0) dataObj.SetId(model.ID_AUTO);
                try
                {
                    dataObj.Save();
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception ex2)
                {
                    throw ex2;
                }
                finally
                {
                    try { connPool.Close(); }
                    catch (SqlException) { }
                    finally { connPool.Dispose(); }
                }
            }
        }