Ejemplo n.º 1
0
        public JsonResult Update(RadnikRolaViewModel rola)
        {
            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 rolaPom = context.RadnikRolas.Find(rola.RadnikRolaID);

                    rolaPom.RadnikRolaID = rola.RadnikRolaID;
                    rolaPom.RadnikID     = rola.RadnikID;
                    rolaPom.RolaID       = rola.RolaID;

                    context.SaveChanges();
                    return(Json(new { Result = "OK" }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Ejemplo n.º 2
0
        public JsonResult Create(RadnikRolaViewModel rola)
        {
            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())
                {
                    context.RadnikRolas.Add(new RadnikRola
                    {
                        RadnikRolaID = rola.RadnikRolaID,
                        RadnikID     = rola.RadnikID,
                        RolaID       = rola.RolaID
                    });

                    context.SaveChanges();

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