public ActionResult Post(dataJson data) { try { if (ModelState.IsValid) { var contextForEmp = new ContextAR(); var newEmpEntry = new Employee { Id = data.Id, Code = data.Code, Name = data.Name, Surname = data.Surname, Title = data.Title, Sector = data.Sector, Key = data.Key }; contextForEmp.Add(newEmpEntry); contextForEmp.SaveChanges(); return(Content("succes", "text/plain")); } else { return(Content("Bad request", "text/plain")); } } catch (Exception ex) { return(Content(ex.Message, "text/plain")); } }
public ValuesController() { Context = new ContextAR(); JsonSer = new JsonSerializerSettings() { Formatting = Formatting.Indented }; }
public ActionResult Put(dataJson data) { if (ModelState.IsValid) { var ContextAR = new ContextAR(); Employee empToUpdate = ContextAR.employee.Single(emp => emp.Key == data.Key); empToUpdate.Id = data.Id; empToUpdate.Code = data.Code; empToUpdate.Name = data.Name; empToUpdate.Surname = data.Surname; empToUpdate.Title = data.Title; empToUpdate.Sector = data.Sector; ContextAR.SaveChanges(); return(Content("Succes", "text/plain")); } else { return(Content("Something went wrong", "text/plain")); } }