コード例 #1
0
        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);
        }
コード例 #2
0
        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();
        }
コード例 #3
0
 partial void UpdateGoal(Goal instance);
コード例 #4
0
 partial void DeleteGoal(Goal instance);
コード例 #5
0
 partial void InsertGoal(Goal instance);
コード例 #6
0
		private void detach_Goals(Goal entity)
		{
			this.SendPropertyChanging();
			entity.GoalType = null;
		}
コード例 #7
0
		private void attach_Goals(Goal entity)
		{
			this.SendPropertyChanging();
			entity.GoalType = this;
		}
コード例 #8
0
		private void detach_Goals(Goal entity)
		{
			this.SendPropertyChanging();
			entity.UserProfile = null;
		}
コード例 #9
0
		private void attach_Goals(Goal entity)
		{
			this.SendPropertyChanging();
			entity.UserProfile = this;
		}