public ActionResult Edit(int?id)
        {
            if (id == null && !Request.IsAjaxRequest())
            {
                string ErrorMessage = "Id Materiel manquant";
                return(RedirectToAction("Index", new { MessageErreur = ErrorMessage }));
            }
            Materiel unMateriel = this.materielService.GetMaterielById(id);

            if (unMateriel == null && !Request.IsAjaxRequest())
            {
                return(HttpNotFound());
            }

            this.IsFromBlocInventaire();

            FormMaterielViewModels formModel = this.GetFormMateriel(true, unMateriel);

            if (Request.IsAjaxRequest())
            {
                return(PartialView("_AjaxEditMateriel", formModel));
            }
            else
            {
                return(View(formModel));
            }
        }
        private FormMaterielViewModels GetFormMateriel(bool isEdit, Materiel unMateriel = null, int?blocInventaireId = null)
        {
            int?BlocInventaireId = null;

            if (unMateriel != null)
            {
                BlocInventaireId = unMateriel.BlocInventaireID;
            }
            else if (blocInventaireId != null)
            {
                BlocInventaireId = blocInventaireId;
            }

            int?TypeMaterielId = null;

            if (unMateriel != null)
            {
                TypeMaterielId = unMateriel.TypeMaterielID;
            }


            if (unMateriel == null)
            {
                unMateriel          = new Materiel();
                unMateriel.Active   = true;
                unMateriel.Quantite = 1;
                unMateriel.Tester   = true;
                unMateriel.Rank     = 1;

                if (blocInventaireId != null)
                {
                    unMateriel.BlocInventaireID = Convert.ToInt32(blocInventaireId);
                }
            }

            FormMaterielViewModels formModel = new FormMaterielViewModels();

            formModel.unMateriel = unMateriel;

            //Gestion des listes
            formModel.listBlocInventaire = new SelectList(this.blocInventaireService.GetBlocsInventaireListe(), "Id", "Nom", BlocInventaireId);
            formModel.listTypeMateriel   = this.selectListHelper.AddFirstItemSelectList(new SelectList(this.typeMaterielService.GetTypeMateriels(), "ID", "Nom"), TypeMaterielId, "Sélectionner");
            //Gestion du mode Edit et du mode Ajax
            formModel.isEdit = isEdit;
            return(formModel);
        }
        public ActionResult AjaxCreate(Materiel unMateriel)
        {
            FormMaterielViewModels formModel = this.GetFormMateriel(false, unMateriel);

            if (ModelState.IsValid)
            {
                ActionControllerResult result = this.materielService.InsertMateriel(unMateriel, User.Identity.GetUserId());
                if (result == ActionControllerResult.FAILURE)
                {
                    ViewBag.ErrorMessage = Constantes.MESSAGE_ERR_NOTIFICATIONS;
                    return(PartialView("_FormContenuMateriel", formModel));
                }
                //Réussi
                this.logService.LogEvenement(LOG_TYPE_EVENT.Create, LOG_TYPE_OBJECT.Materiel, unMateriel.ID, "Création d'un Matériel", null, User.Identity.GetUserId());
                return(Json(string.Empty));
            }
            return(PartialView("_FormContenuMateriel", formModel));
        }
        public ActionResult AjaxEdit([Bind(Include = "ID,Nom,Description,Quantite,Tester,Rank,Active,DateCreation,DateModification,TypeMaterielID,BlocInventaireID")] Materiel unMateriel)
        {
            FormMaterielViewModels formModel = this.GetFormMateriel(false, unMateriel);

            if (ModelState.IsValid)
            {
                ActionControllerResult result = this.materielService.UpdateMateriel(unMateriel, User.Identity.GetUserId());

                if (result == ActionControllerResult.FAILURE)
                {
                    ViewBag.ErrorMessage = Constantes.MESSAGE_ERR_NOTIFICATIONS;
                    return(PartialView("_FormContenuMateriel", formModel));
                }
                //Réussi
                this.logService.LogEvenement(LOG_TYPE_EVENT.Edit, LOG_TYPE_OBJECT.Materiel, unMateriel.ID, "Modification d'un Matériel", null, User.Identity.GetUserId());
                return(Json(string.Empty));
            }
            return(PartialView("_FormContenuMateriel", formModel));
        }
        public ActionResult Create(Materiel unMateriel)
        {
            FormMaterielViewModels formModel = this.GetFormMateriel(false, unMateriel);

            if (ModelState.IsValid)
            {
                //insertion du blocInventaire
                ActionControllerResult result = this.materielService.InsertMateriel(unMateriel, User.Identity.GetUserId());
                //si erreur on affiche un message
                if (result == ActionControllerResult.FAILURE)
                {
                    ViewBag.ErrorMessage = Constantes.MESSAGE_ERR_NOTIFICATIONS;
                    return(View(formModel));
                }
                //Réussi
                this.logService.LogEvenement(LOG_TYPE_EVENT.Create, LOG_TYPE_OBJECT.Materiel, unMateriel.ID, "Création d'un Matériel", null, User.Identity.GetUserId());
                return(RedirectToAction("Index"));
            }
            return(View(formModel));
        }
        public ActionResult Edit([Bind(Include = "ID,Nom,Description,Quantite,Tester,Rank,Active,DateCreation,DateModification,TypeMaterielID,BlocInventaireID")] Materiel unMateriel)
        {
            FormMaterielViewModels formModel = this.GetFormMateriel(false, unMateriel);

            if (ModelState.IsValid)
            {
                ActionControllerResult result = this.materielService.UpdateMateriel(unMateriel, User.Identity.GetUserId());

                if (result == ActionControllerResult.FAILURE)
                {
                    ViewBag.ErrorMessage = Constantes.MESSAGE_ERR_NOTIFICATIONS;

                    this.IsFromBlocInventaire();
                    return(View(formModel));
                }
                //Réussi
                this.logService.LogEvenement(LOG_TYPE_EVENT.Edit, LOG_TYPE_OBJECT.Materiel, unMateriel.ID, "Modification d'un Matériel", null, User.Identity.GetUserId());

                if (Session["isFromBlocInventaire"] != null)
                {
                    if (Convert.ToBoolean(Session["isFromBlocInventaire"]))
                    {
                        return(RedirectToAction("Details", "Materiel", new { id = unMateriel.ID, isFromBlocInventaire = true }));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            this.IsFromBlocInventaire();
            return(View(formModel));
        }
        public ActionResult GetFormCreate(int?blocInventaireId = null)
        {
            FormMaterielViewModels formModel = GetFormMateriel(false, blocInventaireId: blocInventaireId);

            return(PartialView("_AjaxAddMateriel", formModel));
        }
        public ActionResult Create()
        {
            FormMaterielViewModels formModel = this.GetFormMateriel(false);

            return(View("Create", formModel));
        }