Exemplo n.º 1
0
        public ActionResult SaveChanges(TopModel model)
        {
            if (!ModelState.IsValid)
            {
                return(null);
            }

            T_Top entity = TopModel.ModelToEntity(model);

            // Save add action
            if (model.top_id <= 0)
            {
                _context.Add(entity);
                _context.SaveChanges();
                Log.Info(string.Format("Edit top id={0} name={1}", entity.top_id, entity.top_title));

                return(GenerateJson(entity, true, "Nouveau classement ajouté."));
            }
            // Save edit action
            else
            {
                _context.Edit(entity);
                _context.SaveChanges();
                Log.Info(string.Format("Create top id={0} name={1}", entity.top_id, entity.top_title));

                return(GenerateJson(entity, false, "Classement modifié."));
            }
        }
Exemplo n.º 2
0
        public ActionResult Remove(int id)
        {
            T_Top entity = _context.GetById(id);

            _context.Remove(entity);
            _context.SaveChanges();
            Log.Info(string.Format("Remove top id={0} name={1}", entity.top_id, entity.top_title));

            return(Content("Classement supprimé.", "text/html"));
        }
Exemplo n.º 3
0
 private ActionResult GenerateJson(T_Top entity, bool isNew, string msg)
 {
     return(Json(new
     {
         entityName = "Top",
         id = entity.top_id,
         fields = new
         {
             top_title = entity.top_title
         },
         isNew = isNew,
         msg = msg
     }));
 }