public JsonResult Create(UlogaViewModel ulogaViewModel) { try { if (!ModelState.IsValid) { return(Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." })); } using (var context = new ProdavnicaContext()) { Uloga uloga = new Uloga { UlogaID = ulogaViewModel.UlogaID, Naziv = ulogaViewModel.Naziv }; context.Ulogas.Add(uloga); context.SaveChanges(); return(Json(new { Result = "OK", Record = uloga })); } } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }
public JsonResult UpdateUloga(UlogaViewModel ulogaVM) { try { if (!ModelState.IsValid) { return(Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." })); } using (var context = new ProdavnicaContext()) { Uloga ulogaUpdate = context.Ulogas.Find(ulogaVM.UlogaId); ulogaUpdate.UlogaId = ulogaVM.UlogaId; ulogaUpdate.Naziv = ulogaVM.Naziv; context.SaveChanges(); } return(Json(new { Result = "OK" })); } catch (Exception ex) { return(Json(new { Result = "ERROR", Message = ex.Message })); } }