コード例 #1
0
        public JsonResult Create(GrupeViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." }));
                }

                using (var context = new LMContext())
                {
                    Grupe model = new Grupe
                    {
                        Naziv = viewModel.Naziv,
                    };
                    context.Grupes.Add(model);
                    context.SaveChanges();

                    return(Json(new { Result = "OK", Record = model }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
コード例 #2
0
        public JsonResult Update(GrupeViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." }));
                }
                using (var context = new LMContext())
                {
                    Grupe model = context.Grupes.Find(viewModel.GrupaID);
                    model.Naziv = viewModel.Naziv;
                    context.SaveChanges();
                }

                return(Json(new { Result = "OK" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }