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

            RoleFormModel RoleFormModel = new RoleFormModel();

            if (Id != 0)
            {
                Role Role = roleService.GetRole(Id);
                RoleFormModel = AutoMapper.Mapper.Map<Role, RoleFormModel>(Role);
            }

            RoleFormModel = getDropDownValues(RoleFormModel);

            return View("RoleCreate", RoleFormModel);
        }
        public ActionResult Create(RoleFormModel Rolemodel)
        {
            try
            {
                Role Role = AutoMapper.Mapper.Map<RoleFormModel, Role>(Rolemodel);

                if (ModelState.IsValid)
                {
                    if (Role.ID == 0)
                    {
                        roleService.CreateRole(Role);
                    }
                    else
                    {
                        roleService.EditRole(Role);
                    }
                    ViewBag.successMessage = "Role 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;
                }
                Rolemodel = new RoleFormModel();
                Rolemodel = getDropDownValues(Rolemodel);
            }
            catch (Exception ex)
            {
                ViewBag.successMessage = "";
                ViewBag.errorMessage = string.Format("Error in Role Save : {0}", ex.Message);
            }

            return View("RoleCreate", Rolemodel);
        }
        public ActionResult Details(long Id)
        {
            RoleFormModel RoleDetails = new RoleFormModel();

            Role Role = roleService.GetRole(Id);

            RoleDetails = AutoMapper.Mapper.Map<Role, RoleFormModel>(Role);

            RoleDetails.ReportsToName = Role.ReportsTo != null && Role.ReportsTo != 0 ? roleService.GetRole(long.Parse(Role.ReportsTo.ToString())).Name : string.Empty;

            return View("RoleDetails", RoleDetails);
        }
        private RoleFormModel getDropDownValues(RoleFormModel RoleFormModel)
        {
            List<SelectListItem> items = new List<SelectListItem>();

            var roles = roleService.GetRoles();

            if (RoleFormModel.ID > 0)
                roles = roles.Where(x => x.ID != RoleFormModel.ID);

            items.AddRange(roles.OrderBy(role => role.Name)
               .Select(role =>
                   new SelectListItem
                   {
                       Selected = (role.ID == RoleFormModel.ID),
                       Text = role.Name,
                       Value = role.ID.ToString()
                   }));

            RoleFormModel.RoleList = items;

            return RoleFormModel;
        }