public JsonResult CreateActivity(ActivityModel model) { if (!ModelState.IsValid) { return Json(new { Result = "ERROR", Message = "Form is not valid! " + "Please correct it and try again." }); } try { JourListDMContainer dm = new JourListDMContainer(); Activity newActivity = new Activity(); newActivity.Points = model.Points; newActivity.Description = model.Description; newActivity.Unit = dm.Units.Single(z => z.Id == model.UnitId); newActivity.Quantity = model.Quantity; dm.AddToActivities(newActivity); dm.SaveChanges(); model.Id = newActivity.Id; return Json(new { Result = "OK", Record = model }); } catch (Exception e) { return Json(new { Result = "ERROR", Message = e.Message }); } }