private LeadFormModel getLeadDropDownValues(LeadFormModel leadformmodel)
        {
            IEnumerable<LeadSourceEnum> sourcetypes = Enum.GetValues(typeof(LeadSourceEnum))
                                                     .Cast<LeadSourceEnum>();

            leadformmodel.LeadSourceList = from src in sourcetypes
                                           select new SelectListItem
                                           {
                                               Text = src.ToString(),
                                               Value = ((int)src).ToString()
                                           };

            IEnumerable<LeadStatusEnum> statustypes = Enum.GetValues(typeof(LeadStatusEnum))
                                                      .Cast<LeadStatusEnum>();

            leadformmodel.LeadStatusList = from src in statustypes
                                           select new SelectListItem
                                           {
                                               Text = src.ToString(),
                                               Value = ((int)src).ToString()
                                           };

            if (leadformmodel.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 == leadformmodel.AssignedTo),
                   Text = grp.Name,
                   Value = grp.ID.ToString()
               }));

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

                var users = userService.GetUsers();

                if (leadformmodel.AssignedTo == 0)
                {
                    leadformmodel.AssignedTo = users.FirstOrDefault(s => s.UserID == Session["UserID"].ToString()).ID;
                }

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

                leadformmodel.GrpUserList = items;
            }

            leadformmodel.LeadSourceName = ((LeadSourceEnum)leadformmodel.LeadSource).ToString();
            leadformmodel.LeadStatusName = ((LeadStatusEnum)leadformmodel.LeadStatus).ToString();

            return leadformmodel;
        }
        public ActionResult Create(LeadFormModel leadModel)
        {
            try
            {
                Lead lead = AutoMapper.Mapper.Map<LeadFormModel, Lead>(leadModel);

                lead.LeadSource = ((LeadSourceEnum)leadModel.LeadSource).ToString();
                lead.LeadStatus = ((LeadStatusEnum)leadModel.LeadStatus).ToString();

                //var errors = LeadService.Validate.ToList(); //To do Later
                //ModelState.AddModelErrors(errors);

                if (ModelState.IsValid)
                {
                    if (lead.ID == 0)
                    {
                        leadService.CreateLead(lead);
                    }
                    else
                    {
                        leadService.EditLead(lead);
                    }
                    ViewBag.successMessage = "Lead 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;
                }
                //leadModel = new LeadFormModel();
                leadModel = getLeadDropDownValues(leadModel);
            }
            catch (Exception ex)
            {
                ViewBag.successMessage = "";
                ViewBag.errorMessage = string.Format("Error in Lead Save : {0}", ex.Message);
                leadModel = getLeadDropDownValues(leadModel);
            }

            return View("LeadCreate", leadModel);
        }
        public ActionResult Details(long Id)
        {
            LeadFormModel leadDetails = new LeadFormModel();

            Lead lead = leadService.GetLead(Id);

            leadDetails = AutoMapper.Mapper.Map<Lead, LeadFormModel>(lead);

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

            leadDetails.LeadSourceName = lead.LeadSource;
            leadDetails.LeadStatusName = lead.LeadStatus;

            return View("LeadDetails", leadDetails);
        }
        public ActionResult Create(long Id = 0)
        {
            ViewBag.SuccessMessage = "";

            LeadFormModel leadformmodel = new LeadFormModel();

            if (Id != 0)
            {
                Lead lead = leadService.GetLead(Id);
                leadformmodel = AutoMapper.Mapper.Map<Lead, LeadFormModel>(lead);
                leadformmodel.LeadSource = (int)Enum.Parse(typeof(LeadSourceEnum), lead.LeadSource);
                leadformmodel.LeadStatus = (int)Enum.Parse(typeof(LeadStatusEnum), lead.LeadStatus);
            }

            leadformmodel = getLeadDropDownValues(leadformmodel);

            return View("LeadCreate", leadformmodel);
        }