public ActionResult Create(long Id = 0)
        {
            ViewBag.SuccessMessage = "";
            CampaignFormModel CampaignFormModel = new CampaignFormModel();

            if (Id != 0)
            {
                Campaign campaign = campaignService.GetCampaign(Id);
                CampaignFormModel = AutoMapper.Mapper.Map<Campaign, CampaignFormModel>(campaign);
            }

            CampaignFormModel = getDropDownValues(CampaignFormModel);

            return View("CampaignCreate", CampaignFormModel);
        }
        public ActionResult Details(long Id)
        {
            CampaignFormModel campaignDetails = new CampaignFormModel();

            Campaign campaign = campaignService.GetCampaign(Id);

            campaignDetails = AutoMapper.Mapper.Map<Campaign, CampaignFormModel>(campaign);

            if (campaignDetails.AssignedToUserGroup == UserGroup.group)
            {
                campaignDetails.AssignedToName = groupService.GetGroup(campaignDetails.AssignedTo) != null ? groupService.GetGroup(campaignDetails.AssignedTo).Name : string.Empty;
            }
            else
            {
                campaignDetails.AssignedToName = userService.GetUser(campaignDetails.AssignedTo) != null ? userService.GetUser(campaignDetails.AssignedTo).Name : string.Empty;
            }

            if(campaignDetails.ProductID != null)
                campaignDetails.ProductName = productService.GetProduct(long.Parse(campaignDetails.ProductID.ToString())) != null ? productService.GetProduct(long.Parse(campaignDetails.ProductID.ToString())).ProductName : string.Empty;

            campaignDetails.ClosingDate = Convert.ToDateTime(campaignDetails.ClosingDate);

            return View("CampaignDetails", campaignDetails);
        }
        private CampaignFormModel getDropDownValues(CampaignFormModel CampaignFormModel)
        {
            IEnumerable<CampaignTypesEnum> campaignTypes = Enum.GetValues(typeof(CampaignTypesEnum))
                                                     .Cast<CampaignTypesEnum>();

            CampaignFormModel.CampaignTypes = from src in campaignTypes
                                              select new SelectListItem
                                              {
                                                  Text = src.ToString(),
                                                  Value = src.ToString()
                                              };

            IEnumerable<CampaignStatusEnum> campaignstatus = Enum.GetValues(typeof(CampaignStatusEnum))
                                                                 .Cast<CampaignStatusEnum>();

            CampaignFormModel.CampaignStatuses = from src in campaignstatus
                                                 select new SelectListItem
                                                 {
                                                     Text = src.ToString(),
                                                     Value = src.ToString()
                                                 };

            IEnumerable<ExpectedResponsesEnum> expectedResponses = Enum.GetValues(typeof(ExpectedResponsesEnum))
                                                                .Cast<ExpectedResponsesEnum>();

            CampaignFormModel.ExpectedResponses = from src in expectedResponses
                                                  select new SelectListItem
                                                  {
                                                      Text = src.ToString(),
                                                      Value = src.ToString()
                                                  };

            List<SelectListItem> productitems = new List<SelectListItem>();

            var products = productService.GetProducts();

            if(CampaignFormModel.ProductID != null )
                CampaignFormModel.ProductName = products.Where(x => x.ID == CampaignFormModel.ProductID).FirstOrDefault().ProductName;

            productitems.AddRange(products.OrderBy(prt => prt.ProductName)
            .Select(prt =>
                new SelectListItem
                {
                    Selected = (prt.ID == CampaignFormModel.ProductID),
                    Text = prt.ProductName,
                    Value = prt.ID.ToString()
                }));

            CampaignFormModel.Products = productitems;

            if (CampaignFormModel.AssignedToUserGroup == UserGroup.group)
            {
                var groups = groupService.GetGroups();

                List<SelectListItem> grpItems = new List<SelectListItem>();

                grpItems.AddRange(groups.OrderBy(grp => grp.Name)
                .Select(grp =>
               new SelectListItem
               {
                   Selected = (grp.ID == CampaignFormModel.AssignedTo),
                   Text = grp.Name,
                   Value = grp.ID.ToString()
               }));

                CampaignFormModel.GrpUserList = grpItems;
            }
            else
            {
                CampaignFormModel.AssignedToUserGroup = UserGroup.user;

                var users = userService.GetUsers();

                List<SelectListItem> items = new List<SelectListItem>();
                items.AddRange(users.OrderBy(user => user.Name)
                 .Select(user =>
                new SelectListItem
                {
                    Selected = (user.ID == CampaignFormModel.AssignedTo),
                    Text = user.Name,
                    Value = user.ID.ToString()
                }));

                CampaignFormModel.GrpUserList = items;
            }

            return CampaignFormModel;
        }
        public ActionResult Create(CampaignFormModel campaignModel)
        {
            try
            {

                Campaign campaign = AutoMapper.Mapper.Map<CampaignFormModel, Campaign>(campaignModel);

                if (ModelState.IsValid)
                {
                    if (campaignModel.ID == 0)
                        campaignService.CreateCampaign(campaign);
                    else
                        campaignService.EditCampaign(campaign);

                    ViewBag.successMessage = "Campaign Saved Successfully";
                    ViewBag.errorMessage = "";
                }
                else
                {
                    string validationErrors = string.Join(",", ModelState.Values.Where(E => E.Errors.Count > 0)
                    .SelectMany(E => E.Errors).Select(E => E.ErrorMessage).ToArray());

                    ViewBag.successMessage = "";
                    ViewBag.errorMessage = validationErrors;
                }

                campaignModel = getDropDownValues(campaignModel);
            }
            catch (Exception ex)
            {
                ViewBag.successMessage = "";
                ViewBag.errorMessage = string.Format("Error in Campaign Save : {0}", ex.Message);
                campaignModel = getDropDownValues(campaignModel);
            }

            return View("CampaignCreate", campaignModel);
        }