public ActionResult AjaxCreate(NewFormSortieStockViewModel formSortieStock)
        {
            NewFormSortieStockViewModel formModel = this.GetFormAjax(formSortieStock.idMateriel, formSortieStock.quantite);

            if (ModelState.IsValid)
            {
                if (formSortieStock.stockSortieID > 0 && formSortieStock.stockEntreeID > 0 && formSortieStock.quantite > 0)
                {
                    ActionControllerResult result = this.sortieStockService.InsertSortieStock(formSortieStock.stockSortieID, formSortieStock.stockEntreeID, formSortieStock.quantite, User.Identity.GetUserId());
                    if (result == ActionControllerResult.FAILURE)
                    {
                        ViewBag.ErrorMessage = Constantes.MESSAGE_ERR_NOTIFICATIONS;
                        return(PartialView("_FormContenuSortieStock", formModel));
                    }
                    this.logService.LogEvenement(LOG_TYPE_EVENT.Create, LOG_TYPE_OBJECT.SortieStockMateriel, null, "Création d'une Sortie de Materiel", null, User.Identity.GetUserId());
                    return(Json(string.Empty));
                }
                else
                {
                    ModelState.AddModelError("quantite", "La quantité doit etre supérieur à zéro");
                }
            }

            return(PartialView("_FormContenuSortieStock", formModel));
        }
        private NewFormSortieStockViewModel GetFormAjax(int?idMateriel, int?quantite = null)
        {
            NewFormSortieStockViewModel formModel = new NewFormSortieStockViewModel();

            //Recherche du matériel par son ID
            Materiel unMateriel = this.materielService.GetMaterielById(idMateriel);

            if (unMateriel != null)
            {
                //Affectation des stock du matériel à la liste "listStockSortie" du form
                IEnumerable <StockMateriel> listStockSortie      = this.stockService.GetStockMaterielByMaterielId(Convert.ToInt32(idMateriel));
                Dictionary <string, string> dictionaryItemSortie = new Dictionary <string, string>();
                Dictionary <string, string> dictionaryItemEntree = new Dictionary <string, string>();

                string libelle = "";

                foreach (StockMateriel unStockSortie in listStockSortie)
                {
                    if (unStockSortie.DatePeremption != null)
                    {
                        libelle = "Péremption: " + unStockSortie.DatePeremption.Value.ToString("dd/MM/yyyy");
                    }
                    else
                    {
                        libelle = unStockSortie.Materiel.TypeMateriel.Nom;
                    }
                    dictionaryItemSortie.Add(unStockSortie.ID.ToString(), libelle);
                }

                //Recherches des stocks matériel du même type aux autres emplacements
                IEnumerable <StockMateriel> listTemp = this.stockService.GetStockMaterielByTypeMateriel(Convert.ToInt32(unMateriel.TypeMaterielID)).Where(w => w.MaterielID != unMateriel.ID);
                foreach (StockMateriel unStockEntree in listTemp)
                {
                    libelle = unStockEntree.Materiel.BlocInventaire.Inventaire.Nom + "=>" + unStockEntree.Materiel.BlocInventaire.Nom;
                    if (unStockEntree.DatePeremption != null)
                    {
                        libelle += ": " + unStockEntree.DatePeremption.Value.ToString("dd/MM/yyyy");
                    }
                    dictionaryItemEntree.Add(unStockEntree.ID.ToString(), libelle);
                }

                formModel.listStockSortie = this.selectListHelper.CreateSelectList(dictionaryItemSortie);
                formModel.listStockEntree = this.selectListHelper.CreateSelectList(dictionaryItemEntree);
                formModel.quantite        = Convert.ToInt32(quantite);
                formModel.NomMateriel     = unMateriel.TypeMateriel.Nom;
                formModel.idMateriel      = unMateriel.ID;
            }

            return(formModel);
        }
        public ActionResult GetFormCreate(int?materielID = null)
        {
            NewFormSortieStockViewModel formModel = GetFormAjax(materielID);

            return(PartialView("_AjaxAddSortieStock", formModel));
        }