public JsonResult AddActivity(UserActivity userActivity) { dynamic response = null; try { userActivity.UserId = userActivity.User.UserId; userActivity.ActivityId = userActivity.Activity.ActivityId; userActivity.User = db.Users.Find(userActivity.UserId); userActivity.Activity = db.Activities.Find(userActivity.ActivityId); db.UserActivities.Add(userActivity); db.SaveChanges(); _uaService.CalculateIncentives(userActivity.User.Username); response = new { Success = true, Title = userActivity.Activity.Name, Date = userActivity.Date.ToShortDateString() }; } catch(Exception ex) { response = new { Success = false, Message = ex.Message }; } return Json(response); }
public ActionResult Create(UserActivity userActivity) { if (ModelState.IsValid) { userActivity.UserId = userActivity.User.UserId; userActivity.ActivityId = userActivity.Activity.ActivityId; userActivity.User = db.Users.Find(userActivity.UserId); userActivity.Activity = db.Activities.Find(userActivity.ActivityId); db.UserActivities.Add(userActivity); db.SaveChanges(); _uaService.CalculateIncentives(userActivity.User.Username); return RedirectToAction("Index", new { username = userActivity.User.Username }); } return RedirectToAction("Index", new { username = userActivity.User.Username }); }
public ActionResult Edit(UserActivity useractivity) { if (ModelState.IsValid) { db.Entry(useractivity).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.UserId = new SelectList(db.Users, "UserId", "Username", useractivity.UserId); ViewBag.ActivityId = new SelectList(db.Activities, "ActivityId", "Name", useractivity.ActivityId); _uaService.CalculateIncentives(useractivity.User.Username); return View(useractivity); }