public ActionResult editCampaign(UpdateCampModel model)
        {
            if (ModelState.IsValid)
            {
                model.Campaigns.StatusId     = 1;
                model.Campaigns.IsActive     = true;
                model.Campaigns.EmailContent = TempData["emailContent"].ToString();
                // model.Campaigns.EmailContent=WebUtility.HtmlEncode(model.Campaigns.EmailContent);

                try
                {
                    //dbContext.Entry(model.Campaigns).State = System.Data.Entity.EntityState.Modified;
                    //dbContext.SaveChanges();
                    M_Campaigns.UpdateCampaign(model);
                    return(RedirectToAction("Campaign"));
                }
                catch (M_CustomException ex)
                {
                    if (ex.ErrorCode == 100)
                    {
                        ModelState.AddModelError("error", ex.message);
                        return(RedirectToAction("Campaign"));
                    }
                    else if (ex.ErrorCode == 101)
                    {
                        ModelState.AddModelError("Error", "logical exception");
                        return(RedirectToAction("Campaign"));
                    }
                }
            }
            return(RedirectToAction("Campaign"));
        }
        public ActionResult editCampaign(int?id)
        {
            userID = GetUser();
            UpdateCampModel campaign = new UpdateCampModel();

            try
            {
                // campaign.Campaigns = dbContext.M_Campaigns.Find(id);
                campaign.Campaigns = M_Campaigns.FindCampaign(id);
                //campaign.Subscribers = dbContext.NewLists.Find(campaign.Campaigns.ListId).Subscribers.ToList();
                campaign.Subscribers = M_Campaigns.subscribersToCampaign(campaign.Campaigns.ListId);
                //WebUtility.HtmlDecode(campaign.Campaigns.EmailContent);
                ViewBag.campTypes        = new SelectList(S_CampaignTypes.GetCampTypes(), "CTId", "Name");
                ViewBag.List             = new SelectList(M_List.GetLists(userID), "ListID", "ListName");
                TempData["emailContent"] = campaign.Campaigns.EmailContent;
                return(View("UpdateCamp", campaign));
            }
            catch (M_CustomException ex)
            {
                if (ex.ErrorCode == 100)
                {
                    ModelState.AddModelError("error", ex.message);
                    return(RedirectToAction("Campaign"));
                }
                else if (ex.ErrorCode == 101)
                {
                    ModelState.AddModelError("Error", "logical exception");
                    return(RedirectToAction("Campaign"));
                }
            }
            catch (InvalidOperationException ex)
            {
                M_CustomException obj = new M_CustomException((int)ErorrTypes.others, ex.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL());
                obj.LogException();
                ModelState.AddModelError("Error", "Invalid operation");
                return(RedirectToAction("Campaign"));
            }

            return(RedirectToAction("Campaign"));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Update campaign information to database
 /// </summary>
 /// <param name="model"></param>
 public static void UpdateCampaign(UpdateCampModel model)
 {
     using (dbcontext = new ApplicationDbContext())
     {
         try
         {
             dbcontext.Entry(model.Campaigns).State = System.Data.Entity.EntityState.Modified;
             dbcontext.SaveChanges();
         }
         catch (SqlException ex)
         {
             obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL(), ex.LineNumber);
             obj.LogException();
             throw obj;
         }
         catch (Exception ex)
         {
             obj = new M_CustomException((int)ErorrTypes.others, ex.InnerException.Message, ex.StackTrace, ErorrTypes.others.ToString(), Utlities.GetURL());
             obj.LogException();
             throw obj;
         }
     }
 }