public ActionResult Create(NewCampaignViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.StartDate.Date < DateTime.Now.Date)
                {
                    this.TempData["ErrorMessage"] = "Start date cannot be eariler than today";
                }
                else if (model.StartDate.Date > model.EndDate.Date)
                {
                    this.TempData["ErrorMessage"] = "End date cannot be earlier than start date";
                }
                else
                {
                    Campaign campaign = new Campaign();
                    Mapper.Map(model, campaign);
                    ApplicationUser user = this.data.Users.Find(this.User.Identity.GetUserId());
                    campaign.ManagerId = user.Id;
                    campaign.OfficeId  = user.OfficeId ?? 0;
                    this.data.Campaigns.Add(campaign);
                    this.data.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }

            return(View(model));
        }
        public ActionResult Create(NewCampaignViewModel model)
        {
            if (ModelState.IsValid && (model.StartDate < model.EndDate))
            {
                Campaign campaign = new Campaign()
                {
                    Active      = model.Active,
                    Description = model.Description,
                    EndDate     = model.EndDate,
                    ManagerId   = this.User.Identity.GetUserId(),
                    Price       = model.Price,
                    Product     = model.Product,
                    Script      = model.Script,
                    StartDate   = model.StartDate
                };

                ApplicationUser user = this.data.Users.Find(campaign.ManagerId);
                campaign.OfficeId = user.OfficeId ?? 0;
                this.data.Campaigns.Add(campaign);
                this.data.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
        //GET: Campaigns/Create
        public ActionResult Create()
        {
            var viewModel = new NewCampaignViewModel
            {
                Products = new List <Product>()
            };

            return(View(viewModel));
        }