0

i have a table Rubriqueintermediare with a rubriqueIntermediareId and rubriqueId as a foreign key from the table Rubrique:So in my rubrique intermediare i have a listbox of rubrique i want to compare viewdata list values with dropdownlist selected so to interdict the addition of the same rubriqueintermediare : i tried this code but it didn't work :

[HttpPost]
public JsonResult Save([DataSourceRequest] DataSourceRequest dsRequest, RubriquepointageVM vm)
{
    try
    {
        IEnumerable<RubriqueVM> listRubrique = RefDataManager.GetRefData<RubriqueVM>() as IEnumerable<RubriqueVM>;
        ViewData["CodeRubrique"] = new SelectList(RefDataManager.GetRefData<RubriqueVM>(), "RubriqueId", "CODELIBELLE");

        var Rubriques = listRubrique.AsQueryable();
         List<RubriquepointageVM> lstRubriqueinter = ServiceApplicatif.GetListe();

         if (!(listRubrique.Any(r => r.RubriqueId==(vm.RubriqueId)))){
             ModelState.AddModelError("RubriqueId", "ajout impossible ");
             return Json(ModelState.ToDataSourceResult());
         }else {
           RubriquepointageVM rub = ServiceApplicatif.Save(vm);
           return Json(new[] { vm }.ToDataSourceResult(dsRequest, ModelState));

           DataCache dataCache = new DataCache(CurrentSecurityContext.TenantID);
           dataCache.DropDataCache<RubriquepointageVM>();
            }

    }
    catch (Exception ex)
    {
        LoggerRubriquepointage.Error(string.Format("Exception : {0}", ex.Message.ToString()));
        throw new Exception("Erreur lors de l'enregistrement.");
    }
}

when i put a break point if i have added the same value from the listbox or not it excutes just the else:

 else {
       RubriquepointageVM rub = ServiceApplicatif.Save(vm);
       return Json(new[] { vm }.ToDataSourceResult(dsRequest, ModelState));

       DataCache dataCache = new DataCache(CurrentSecurityContext.TenantID);
       dataCache.DropDataCache<RubriquepointageVM>();
     }
John Saunders
  • 160,644
  • 26
  • 247
  • 397
ODE
  • 285
  • 5
  • 22
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackoverflow.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Apr 29 '14 at 15:19
  • @ John Saunders,ok i understand – ODE Apr 29 '14 at 15:23
  • Why have you added the ! in your if condition? – bilal.haider Apr 29 '14 at 15:23
  • doesn't quite answer your question but the code hides too much functionality to help anyway. try stepping through with F11 and see if every step goes the way you expect it to. Thats how i solve such issues usually. – Dbl Apr 29 '14 at 15:24
  • i tried with F11 and nothing bizar happens !,i didn't know if my test is even correct to interdict to choose from the listbox a value that exisits in the **Rubriqueintermediare** list ??@ Andreas Müller – ODE Apr 29 '14 at 15:34

0 Answers0