Esempio n. 1
0
        public ActionResult Create(Campaign campaign)
        {
            var currentUserId = (Guid)Membership.GetUser().ProviderUserKey;
            campaign.DateCreated = DateTime.Now;
            campaign.UserId = currentUserId;
            campaign.Appoved = true; //default false, approve by admin
            campaign.Active = true; //default false , activate after submit
            campaign.Email = _db.Users.SingleOrDefault(u => u.UserId == currentUserId).Membership.Email;
            campaign.Location = _db.Users.SingleOrDefault(u => u.UserId == currentUserId).Profile.Location;
            campaign.EndDate = DateTime.Now;
            if (ModelState.IsValid)
            {
                _db.Campaigns.Add(campaign);
                _db.SaveChanges();
                return RedirectToAction("Edit", "Campaigns", new { id = campaign.CampaignID });

            }

            ViewBag.AccountId = new SelectList(_db.Accounts, "AccountID", "AccountID", campaign.AccountId);
            ViewBag.CampaignTypeId = new SelectList(_db.CampaignTypes, "CampaignTypeID", "Name", campaign.CampaignTypeId);
            ViewBag.GenreID = new SelectList(_db.Genres, "ID", "Name", campaign.GenreID);
            ViewBag.UserId = new SelectList(_db.Users, "UserId", "UserName", campaign.UserId);
            return View(campaign);
        }
		private void detach_Campaigns(Campaign entity)
		{
			this.SendPropertyChanging();
			entity.Account = null;
		}
		private void attach_Campaigns(Campaign entity)
		{
			this.SendPropertyChanging();
			entity.Account = this;
		}
 partial void DeleteCampaign(Campaign instance);
 partial void UpdateCampaign(Campaign instance);
 partial void InsertCampaign(Campaign instance);
		private void detach_Campaigns2(Campaign entity)
		{
			this.SendPropertyChanging();
			entity.File2 = null;
		}
		private void attach_Campaigns2(Campaign entity)
		{
			this.SendPropertyChanging();
			entity.File2 = this;
		}
		private void detach_Campaigns(Campaign entity)
		{
			this.SendPropertyChanging();
			entity.UserProfile = null;
		}
Esempio n. 10
0
        public ActionResult Edit(Campaign campaign)
        {
            if (campaign == null)return HttpNotFound();

            var currentUserId = (Guid)Membership.GetUser().ProviderUserKey;
            var existingCampaign = _db.Campaigns.Find(campaign.CampaignID);
            if (existingCampaign.UserId != currentUserId) { return HttpNotFound(); }

            if (ModelState.IsValid)
            {
                existingCampaign.Location = campaign.Location;
                existingCampaign.Name = campaign.Name;
                existingCampaign.Location = campaign.Location;
                existingCampaign.Intro = campaign.Intro;
                existingCampaign.Email = campaign.Email;
                existingCampaign.EndDate = campaign.EndDate;
                existingCampaign.CampaignTypeId = campaign.CampaignTypeId;
                existingCampaign.GenreID = campaign.GenreID;

                _db.Entry(existingCampaign).State = EntityState.Modified;
                _db.SaveChanges();
                return RedirectToAction("Details", "Campaigns", new { id = existingCampaign.CampaignID });

            }
            ViewBag.AccountId = new SelectList(_db.Accounts, "AccountID", "AccountID", campaign.AccountId);
            ViewBag.CampaignTypeId = new SelectList(_db.CampaignTypes, "CampaignTypeID", "Name", campaign.CampaignTypeId);
            ViewBag.GenreID = new SelectList(_db.Genres, "ID", "Name", campaign.GenreID);
            ViewBag.UserId = new SelectList(_db.Users, "UserId", "UserName", campaign.UserId);
            return View(campaign);
        }