public static CategoriePratiquant ToDTO(this CategoriePratiquantModel model)
        {
            CategoriePratiquant result = new CategoriePratiquant();

            if (model.Id != 0)
            {
                result.Id = model.Id;
            }
            result.Nom    = model.Nom;
            result.AgeMin = model.AgeMin;
            result.AgeMax = model.AgeMax;

            return(result);
        }
 /// <summary>
 /// Deletes the specified model.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <returns></returns>
 public JsonResult Delete(CategoriePratiquantModel model)
 {
     try
     {
         var dbItem = this.repository.Read(model.Id);
         if (dbItem != null)
         {
             repository.Delete(dbItem);
             return(Json(new { success = true }));
         }
         return(Json(new { success = false }));
     }
     catch
     {
         throw;
     }
 }
        /// <summary>
        /// Updates the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public JsonResult Update(CategoriePratiquantModel model)
        {
            try
            {
                var dbmodel = this.repository.Read(m => m.Id == model.Id).First();
                dbmodel.AgeMax = model.AgeMax;
                dbmodel.AgeMin = model.AgeMin;
                dbmodel.Duree  = model.Duree;
                dbmodel.Nom    = model.Nom;

                this.repository.Update(dbmodel);
                return(Json(dbmodel.ToModel()));
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// Creates the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public JsonResult Create(CategoriePratiquantModel model)
        {
            try
            {
                var dbitem = new CategoriePratiquant
                {
                    Nom          = model.Nom,
                    AgeMin       = model.AgeMin,
                    AgeMax       = model.AgeMax,
                    Duree        = model.Duree,
                    Competiteurs = new List <Competiteur>(),
                    Epreuves     = new List <Epreuve>(),
                };

                this.repository.Create(dbitem);
                return(Json(dbitem.ToModel()));
            }
            catch
            {
                throw;
            }
        }