public JsonResult Update(SektorViewModel 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()) { var sektorEdit = context.Sektors.Find(viewModel.SektorID); sektorEdit.SektorID = viewModel.SektorID; sektorEdit.Naziv = viewModel.Naziv; context.SaveChanges(); return(Json(new { Result = "OK" })); } } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public JsonResult Create(SektorViewModel 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()) { var noviSektor = new Sektor { Naziv = viewModel.Naziv }; context.Sektors.Add(noviSektor); context.SaveChanges(); return(Json(new { Result = "OK", Record = noviSektor })); } } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }