Exemple #1
0
        public JsonResult Create(GrupaRadnikViewModel viewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { Result = "ERROR", Message = "Korisnicko ime je zauzeto!" }));
                }

                using (var context = new LMContext())
                {
                    var model = new GrupaRadnik
                    {
                        GrupaRadnikID = viewModel.GrupaRadnikID,
                        RadnikID      = viewModel.RadnikID,
                        GrupaID       = viewModel.GrupaID
                    };
                    context.GrupaRadniks.Add(model);
                    context.SaveChanges();
                    return(Json(new { Result = "OK", Record = model }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Exemple #2
0
        public JsonResult Update(GrupaRadnikViewModel 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 model = context.GrupaRadniks.Find(viewModel.GrupaRadnikID);
                    model.GrupaID  = viewModel.GrupaID;
                    model.RadnikID = viewModel.RadnikID;
                    context.SaveChanges();
                }
                return(Json(new { Result = "OK" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }