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 }); } }
public JsonResult ActivityList() { try { JourListDMContainer dm = new JourListDMContainer(); List<ActivityModel> list = new List<ActivityModel>(); foreach (var a in dm.Activities)//.Where(z => z.Active == true)) { ActivityModel atemp = new ActivityModel(); atemp.Id = a.Id; atemp.Description = a.Description; atemp.Points = a.Points; atemp.Active = a.Active; atemp.UnitId = a.Unit.Id; atemp.Quantity = a.Quantity; list.Add(atemp); } return Json(new { Result = "OK", Records = list }); } catch (Exception e) { return Json(new { Result = "ERROR", Message = e.Message }); } }