// GET: Operator/CallResults/Create
        public ActionResult Create()
        {
            NewCallResultModel model = new NewCallResultModel();

            this.SetCampaignsAndStatuses(model);
            return(View(model));
        }
        public ActionResult Create(NewCallResultModel model)
        {
            if (ModelState.IsValid)
            {
                if (this.data.Statuses.Find(model.StatusId) == null)
                {
                    this.TempData["ErrorMessage"] = "Invalid status";
                }

                if (this.GetCampaignsForUser().FirstOrDefault(c => c.CampaignId == model.CampaignId) == null)
                {
                    this.TempData["ErrorMessage"] = "Invalid campaign";
                }

                if (this.TempData["ErrorMessage"] != null)
                {
                    this.SetCampaignsAndStatuses(model);
                    return(View(model));
                }

                CallResult callResult = new CallResult();
                Mapper.Map(model, callResult);
                callResult.OperatorId = this.User.Identity.GetUserId();
                callResult.CallDate   = DateTime.Now;
                this.data.CallResults.Add(callResult);
                this.data.SaveChanges();
                return(RedirectToAction("Index"));
            }

            this.SetCampaignsAndStatuses(model);
            return(View(model));
        }
 private void SetCampaignsAndStatuses(NewCallResultModel model)
 {
     model.Statuses  = this.GetStatuses();
     model.Campaigns = this.GetCampaigns();
 }