public ActionResult Create_Add(Goal goal) { var currentUserId = (Guid)Membership.GetUser().ProviderUserKey; Campaign campaign = _db.Campaigns.Find(goal.CampaignID); if (campaign == null)return HttpNotFound(); if (campaign.Creator.UserId != currentUserId)return HttpNotFound(); if (ModelState.IsValid) { try { goal.Approved = true; goal.UserID = currentUserId; goal.DateCreated = DateTime.Today; goal.Status = "Approved"; goal.IsDeactivated = false; goal.CurrentQTY = "0"; _db.Goals.Add(goal); _db.SaveChanges(); ViewBag.Message = "Goals Saved"; return PartialView("_CampaignGoals",campaign.Goals); } catch (EntityException es) { ViewBag.GoalTypeID = new SelectList(_db.GoalTypes, "GoalTypeID", "Name"); ViewBag.Message = es; return PartialView("_CampaignGoals", campaign.Goals); } } ViewBag.GoalTypeID = new SelectList(_db.GoalTypes, "GoalTypeID", "Name"); return PartialView("_CampaignGoals", campaign.Goals); }
public ActionResult Edit(Goal goal) { if (goal == null)return HttpNotFound(); var currentUserId = (Guid)Membership.GetUser().ProviderUserKey; var existingGoal = _db.Goals.Find(goal.GoalID); if (existingGoal.UserID != currentUserId)return HttpNotFound(); Campaign campaign = existingGoal.Campaign; if (campaign == null)return HttpNotFound(); if (campaign.Creator.UserId != (Guid)Membership.GetUser().ProviderUserKey) { return HttpNotFound(); } if (ModelState.IsValid) { try { existingGoal.GoalTypeID = goal.GoalTypeID; existingGoal.Name = goal.Name; existingGoal.Private = goal.Private; existingGoal.QtyMax = goal.QtyMax; existingGoal.TargetNum = goal.TargetNum; _db.Entry(existingGoal).State = EntityState.Modified; _db.SaveChanges(); ViewBag.Message = "Goal Saved"; return RedirectToAction("Index"); } catch { ViewBag.Message = "Goal Not Saved"; return View(); } } ViewBag.GoalTypeID = new SelectList(_db.GoalTypes, "GoalTypeID", "Name", goal.GoalTypeID); return View(); }
partial void UpdateGoal(Goal instance);
partial void DeleteGoal(Goal instance);
partial void InsertGoal(Goal instance);
private void detach_Goals(Goal entity) { this.SendPropertyChanging(); entity.GoalType = null; }
private void attach_Goals(Goal entity) { this.SendPropertyChanging(); entity.GoalType = this; }
private void detach_Goals(Goal entity) { this.SendPropertyChanging(); entity.UserProfile = null; }
private void attach_Goals(Goal entity) { this.SendPropertyChanging(); entity.UserProfile = this; }