Example #1
0
        public ActionResult CreateEdit(NccPost post)
        {
            if (ModelState.IsValid)
            {
                var author = _nccUserService.Get(User.GetUserId());
                post.Author = author;
                post.Status = EntityStatus.Active;
                _nccPostService.Save(post);
                TempData["SuccessMessage"] = "Post save successful";
            }

            PreparePostCreateEditView();

            return(View(post));
        }
Example #2
0
        public JsonResult ManageAjax(int draw, int start, int length)
        {
            var  data            = new List <object>();
            long recordsTotal    = 0;
            long recordsFiltered = 0;

            try
            {
                string searchText = HttpContext.Request.Form["search[value]"];
                searchText = searchText.Trim();
                #region OrderBy and Direction
                string orderBy  = HttpContext.Request.Form["order[0][column]"];
                string orderDir = HttpContext.Request.Form["order[0][dir]"];
                if (!string.IsNullOrEmpty(orderDir))
                {
                    orderDir = orderDir.ToUpper();
                }
                if (!string.IsNullOrEmpty(orderBy))
                {
                    switch (orderBy)
                    {
                    case "0":
                        orderBy = "name";
                        break;

                    default:
                        orderBy = "";
                        break;
                    }
                }
                #endregion

                recordsTotal    = _nccCategoryService.Count(false, searchText);
                recordsFiltered = recordsTotal;
                List <NccCategory> itemList       = _nccCategoryService.Load(start, length, false, searchText, orderBy, orderDir);
                string             controllerName = "Category";
                foreach (var item in itemList)
                {
                    var str  = new List <string>();
                    var temp = "";
                    #region Title
                    temp = "";
                    if (GlobalContext.WebSite.IsMultiLangual)
                    {
                        foreach (var details in item.CategoryDetails)
                        {
                            if (!string.IsNullOrEmpty(temp))
                            {
                                temp += "<br />";
                            }
                            temp += "<b>" + details.Language + ":</b> " + details.Title;
                        }
                    }
                    else
                    {
                        temp = item.CategoryDetails.Where(x => x.Language == GlobalContext.WebSite.Language).FirstOrDefault().Title;
                    }
                    str.Add(temp);
                    #endregion
                    str.Add("<img src=" + item.CategoryImage + " style='max-width:300px;max-height:100px;'>");
                    if (item.Parent != null)
                    {
                        str.Add(item.Parent?.CategoryDetails?.FirstOrDefault()?.Title);
                    }
                    else
                    {
                        str.Add("-");
                    }

                    if (item.Posts.Count > 0)
                    {
                        str.Add(item.Posts.Count.ToString());
                    }
                    else
                    {
                        str.Add("-");
                    }

                    if (item.CreateBy == item.ModifyBy)
                    {
                        str.Add(_nccUserService.Get(item.CreateBy)?.UserName);
                    }
                    else
                    {
                        str.Add("<b>Cr:</b> " + _nccUserService.Get(item.CreateBy)?.UserName + "<br /><b>Mo:</b> " + _nccUserService.Get(item.ModifyBy)?.UserName);
                    }

                    if (item.CreationDate == item.ModificationDate)
                    {
                        str.Add(item.CreationDate.ToString("yyyy-MM-dd hh:mm tt"));
                    }
                    else
                    {
                        str.Add("<b>Cr:</b> " + item.CreationDate.ToString("yyyy-MM-dd hh:mm tt") + "<br /><b>Mo:</b> " + item.ModificationDate.ToString("yyyy-MM-dd hh:mm tt"));
                    }

                    str.Add(item.Status.ToString());

                    string actionLink = " <a href='" + Url.Action("CreateEdit", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-primary btn-outline'>Edit</a> ";
                    if (item.Status == EntityStatus.Active)
                    {
                        actionLink += " <a href='" + Url.Action("StatusUpdate", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-danger btn-outline'>Inactive</a> ";
                    }
                    else
                    {
                        actionLink += " <a href='" + Url.Action("StatusUpdate", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-success btn-outline'>Active</a> ";
                    }
                    actionLink += " <a href='" + Url.Action("Delete", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-danger'>Delete</a> ";
                    if (GlobalContext.WebSite.IsMultiLangual == true)
                    {
                        actionLink += "";
                        foreach (var Details in item.CategoryDetails)
                        {
                            actionLink += " <a href='/" + Details.Language + "/Category/" + Details.Slug + "' target='_blank' class='btn btn-outline btn-info btn-xs'><i class='fa fa-eye'></i> " + Details.Language + "</a> ";
                        }
                    }
                    else
                    {
                        actionLink += " <a href='/Category/" + item.CategoryDetails.Where(x => x.Language == GlobalContext.WebSite.Language).FirstOrDefault().Slug + "'  target='_blank' class='btn btn-outline btn-info btn-xs'><i class='fa fa-eye'></i> " + GlobalContext.WebSite.Language + "</a> ";
                    }
                    str.Add(actionLink);
                    data.Add(str);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(Json(new
            {
                draw = draw,
                recordsTotal = recordsTotal,
                recordsFiltered = recordsFiltered,
                start = start,
                length = length,
                data = data
            }));
        }
        public JsonResult ManageAjax(int draw, int start, int length)
        {
            var CommentStatus = Enum.GetValues(typeof(NccComment.NccCommentStatus)).Cast <NccComment.NccCommentStatus>().Select(v => new SelectListItem
            {
                Text  = v.ToString(),
                Value = ((int)v).ToString()
            }).ToList();

            var  data            = new List <object>();
            long recordsTotal    = 0;
            long recordsFiltered = 0;

            try
            {
                string searchText = HttpContext.Request.Form["search[value]"];
                searchText = searchText.Trim();
                #region OrderBy and Direction
                string orderBy  = HttpContext.Request.Form["order[0][column]"];
                string orderDir = HttpContext.Request.Form["order[0][dir]"];
                if (!string.IsNullOrEmpty(orderDir))
                {
                    orderDir = orderDir.ToUpper();
                }
                if (!string.IsNullOrEmpty(orderBy))
                {
                    switch (orderBy)
                    {
                    case "0":
                        orderBy = "name";
                        break;

                    default:
                        orderBy = "";
                        break;
                    }
                }
                #endregion

                recordsTotal    = _nccCommentsService.Count(false, GlobalContext.GetCurrentUserId(), searchText);
                recordsFiltered = recordsTotal;
                List <NccComment> itemList       = _nccCommentsService.Load(start, length, false, GlobalContext.GetCurrentUserId(), searchText, orderBy, orderDir);
                string            controllerName = "Comments";
                foreach (var item in itemList)
                {
                    var str = new List <string>();
                    str.Add(item.Post.Name);
                    str.Add(item.Content);
                    str.Add(item.AuthorName);

                    if (item.CreateBy == item.ModifyBy)
                    {
                        str.Add(_nccUserService.Get(item.CreateBy)?.UserName);
                    }
                    else
                    {
                        str.Add("<b>Cr:</b> " + _nccUserService.Get(item.CreateBy)?.UserName + "<br /><b>Mo:</b> " + _nccUserService.Get(item.ModifyBy)?.UserName);
                    }

                    if (item.CreationDate == item.ModificationDate)
                    {
                        str.Add(item.CreationDate.ToString("yyyy-MM-dd hh:mm tt"));
                    }
                    else
                    {
                        str.Add("<b>Cr:</b> " + item.CreationDate.ToString("yyyy-MM-dd hh:mm tt") + "<br /><b>Mo:</b> " + item.ModificationDate.ToString("yyyy-MM-dd hh:mm tt"));
                    }

                    str.Add(item.CommentStatus.ToString());

                    string actionLink = "";
                    foreach (var commentsItem in CommentStatus)
                    {
                        if (item.CommentStatus.ToString() != commentsItem.Text)
                        {
                            actionLink += " <a href='" + Url.Action("StatusUpdate", controllerName, new { id = item.Id.ToString(), commentStatus = commentsItem.Value }) + "' class='btn btn-xs btn-info btn-outline'>" + commentsItem.Text + "</a> ";
                        }
                    }

                    actionLink += " <a href='" + Url.Action("Delete", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-danger'>Delete</a> ";
                    str.Add(actionLink);
                    data.Add(str);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(Json(new
            {
                draw = draw,
                recordsTotal = recordsTotal,
                recordsFiltered = recordsFiltered,
                start = start,
                length = length,
                data = data
            }));
        }
Example #4
0
        public JsonResult ManageAjax(int draw, int start, int length)
        {
            var  data            = new List <object>();
            long recordsTotal    = 0;
            long recordsFiltered = 0;

            try
            {
                string searchText = HttpContext.Request.Form["search[value]"];
                searchText = searchText.Trim();
                #region OrderBy and Direction
                string orderBy  = HttpContext.Request.Form["order[0][column]"];
                string orderDir = HttpContext.Request.Form["order[0][dir]"];
                if (!string.IsNullOrEmpty(orderDir))
                {
                    orderDir = orderDir.ToUpper();
                }
                if (!string.IsNullOrEmpty(orderBy))
                {
                    switch (orderBy)
                    {
                    case "0":
                        orderBy = "name";
                        break;

                    case "5":
                        orderBy = "publishdate";
                        break;

                    default:
                        orderBy = "";
                        break;
                    }
                }
                #endregion

                recordsTotal    = _nccPostService.Count(false, false, false, true, null, null, 0, 0, 0, searchText);
                recordsFiltered = recordsTotal;
                List <NccPost> itemList       = _nccPostService.Load(start, length, false, false, false, true, null, null, 0, 0, 0, searchText, orderBy, orderDir);
                string         controllerName = "Post";
                foreach (var item in itemList)
                {
                    var str  = new List <string>();
                    var temp = "";
                    #region Title
                    temp = "";
                    if (GlobalContext.WebSite.IsMultiLangual)
                    {
                        foreach (var details in item.PostDetails)
                        {
                            if (!string.IsNullOrEmpty(temp))
                            {
                                temp += "<br />";
                            }
                            temp += "<b>" + details.Language + ":</b> " + details.Title;
                        }
                    }
                    else
                    {
                        temp = item.Name;
                    }
                    str.Add(temp);
                    #endregion
                    if (item.Parent != null)
                    {
                        str.Add(item.Parent.PostDetails.FirstOrDefault().Title);
                    }
                    else
                    {
                        str.Add("-");
                    }

                    if (item.CreateBy == item.ModifyBy)
                    {
                        str.Add(_nccUserService.Get(item.CreateBy)?.UserName);
                    }
                    else
                    {
                        str.Add("<b>Cr:</b> " + _nccUserService.Get(item.CreateBy)?.UserName + "<br /><b>Mo:</b> " + _nccUserService.Get(item.ModifyBy)?.UserName);
                    }
                    #region Categories
                    temp = "";
                    foreach (var cat in item.Categories)
                    {
                        if (temp != "")
                        {
                            temp += ", ";
                        }
                        temp += cat.Category.Name;
                    }
                    str.Add(temp);
                    #endregion
                    #region Tags
                    temp = "";
                    foreach (var tag in item.Tags)
                    {
                        if (temp != "")
                        {
                            temp += ", ";
                        }
                        temp += tag.Tag.Name;
                    }
                    str.Add(temp);
                    #endregion

                    str.Add(item.PostStatus == NccPost.NccPostStatus.Published ? NccPost.NccPostStatus.Published.ToString() + ": " + item.PublishDate.ToString("yyyy-MM-dd hh:mm tt") : "Update: " + item.ModificationDate.ToString("yyyy-MM-dd hh:mm tt"));

                    str.Add(item.Layout);
                    str.Add(item.PostType.ToString());
                    str.Add("[Post Id=\"" + item.Id + "\" Post]");

                    string actionLink = " <a href='" + Url.Action("CreateEdit", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-primary btn-outline'>Edit</a> ";
                    //if (item.Status == EntityStatus.Active)
                    //    actionLink += " <a href='" + Url.Action("StatusUpdate", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-danger btn-outline'>Inactive</a> ";
                    //else
                    //    actionLink += " <a href='" + Url.Action("StatusUpdate", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-success btn-outline'>Active</a> ";
                    actionLink += " <a href='" + Url.Action("Delete", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-danger'>Delete</a> ";
                    if (GlobalContext.WebSite.IsMultiLangual == true)
                    {
                        actionLink += "";
                        foreach (var Details in item.PostDetails)
                        {
                            actionLink += " <a href='/" + Details.Language + "/Post/" + Details.Slug + "' target='_blank' class='btn btn-outline btn-info btn-xs'><i class='fa fa-eye'></i> " + Details.Language + "</a> ";
                        }
                    }
                    else
                    {
                        actionLink += " <a href='/Post/" + item.PostDetails.Where(x => x.Language == GlobalContext.WebSite.Language).FirstOrDefault().Slug + "'  target='_blank' class='btn btn-outline btn-info btn-xs'><i class='fa fa-eye'></i> " + item.PostDetails.Where(x => x.Language == GlobalContext.WebSite.Language).FirstOrDefault().Language + "</a> ";
                    }
                    str.Add(actionLink);
                    data.Add(str);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(Json(new
            {
                draw = draw,
                recordsTotal = recordsTotal,
                recordsFiltered = recordsFiltered,
                start = start,
                length = length,
                data = data
            }));
        }
Example #5
0
        public JsonResult ManageAjax(int draw, int start, int length)
        {
            var  data            = new List <object>();
            long recordsTotal    = 0;
            long recordsFiltered = 0;

            try
            {
                string searchText = HttpContext.Request.Form["search[value]"];
                searchText = searchText.Trim();
                #region OrderBy and Direction
                string orderBy  = HttpContext.Request.Form["order[0][column]"];
                string orderDir = HttpContext.Request.Form["order[0][dir]"];
                if (!string.IsNullOrEmpty(orderDir))
                {
                    orderDir = orderDir.ToUpper();
                }
                if (!string.IsNullOrEmpty(orderBy))
                {
                    switch (orderBy)
                    {
                    case "0":
                        orderBy = "name";
                        break;

                    default:
                        orderBy = "";
                        break;
                    }
                }
                #endregion

                recordsTotal    = _neCategoryService.Count(false, searchText);
                recordsFiltered = recordsTotal;
                List <NeCategory> itemList       = _neCategoryService.Load(start, length, false, searchText, orderBy, orderDir);
                string            controllerName = "NeCategory";
                foreach (var item in itemList)
                {
                    var str  = new List <string>();
                    var name = "";
                    if (GlobalContext.WebSite.IsMultiLangual)
                    {
                        foreach (var details in item.Details)
                        {
                            if (!string.IsNullOrEmpty(name))
                            {
                                name += "<br />";
                            }
                            name += "<b>" + details.Language + ":</b> " + details.Name;
                        }
                    }
                    else
                    {
                        name = item.Name;
                    }
                    str.Add(name);
                    str.Add(item.NewsList.Count.ToString());

                    if (item.CreateBy == item.ModifyBy)
                    {
                        str.Add(_nccUserService.Get(item.CreateBy)?.UserName);
                    }
                    else
                    {
                        str.Add("<b>Cr:</b> " + _nccUserService.Get(item.CreateBy)?.UserName + "<br /><b>Mo:</b> " + _nccUserService.Get(item.ModifyBy)?.UserName);
                    }

                    if (item.CreationDate == item.ModificationDate)
                    {
                        str.Add(item.CreationDate.ToString("yyyy-MM-dd HH:mm"));
                    }
                    else
                    {
                        str.Add("<b>Cr:</b> " + item.CreationDate.ToString("yyyy-MM-dd HH:mm") + "<br /><b>Mo:</b> " + item.ModificationDate.ToString("yyyy-MM-dd HH:mm"));
                    }
                    str.Add(item.Status.ToString());

                    string actionLink = " <a href='" + Url.Action("CreateEdit", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-primary btn-outline'>Edit</a> ";
                    if (item.Status == EntityStatus.Active)
                    {
                        actionLink += " <a href='" + Url.Action("StatusUpdate", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-danger btn-outline'>Inactive</a> ";
                    }
                    else
                    {
                        actionLink += " <a href='" + Url.Action("StatusUpdate", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-success btn-outline'>Active</a> ";
                    }
                    actionLink += " <a href='" + Url.Action("Delete", controllerName, new { id = item.Id.ToString() }) + "' class='btn btn-xs btn-danger'>Delete</a> ";

                    str.Add(actionLink);
                    data.Add(str);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(Json(new
            {
                draw = draw,
                recordsTotal = recordsTotal,
                recordsFiltered = recordsFiltered,
                start = start,
                length = length,
                data = data
            }));
        }
Example #6
0
        public void OnAuthorization(AuthorizationFilterContext context)
        {
            var isAuthorized         = false;
            var action               = (ControllerActionDescriptor)context.ActionDescriptor;
            var actionAttributes     = action.MethodInfo.GetCustomAttributes(true);
            var type                 = action.ControllerTypeInfo;
            var moduleName           = type.Assembly.GetName().Name;
            var controllerAttributes = type.GetCustomAttributes(true);

            // Allow actions or controller whoich have AllowAnonymous attribute.
            if (actionAttributes.Where(x => x is AllowAnonymousAttribute).Count() > 0)
            {
                return;
            }

            if (controllerAttributes.Where(x => x is AllowAnonymousAttribute).Count() > 0)
            {
                if (actionAttributes.Where(x => x is NccAuthorize).Count() == 0)
                {
                    return;
                }
            }

            var user = context.HttpContext.User;

            if (user == null)
            {
                context.Result = new ChallengeResult(new AuthenticationProperties());
                context.HttpContext.Items["ErrorMessage"] = "You are not authenticated.";
                context.HttpContext.Response.Redirect("/Home/NotAuthorized");
                return;
            }

            var nccUser = _cache.GetNccUser(user.GetUserId());

            if (nccUser == null)
            {
                nccUser = _nccUserService.Get(user.GetUserId());
                if (nccUser != null)
                {
                    _cache.SetNccUser(nccUser);
                }
            }

            if (nccUser == null)
            {
                context.Result = new ChallengeResult(new AuthenticationProperties());
                context.HttpContext.Items["ErrorMessage"] = "No user found.";
                context.HttpContext.Response.Redirect("/Home/NotAuthorized");
                return;
            }

            if (user.IsInRole(NccCmsRoles.SuperAdmin))
            {
                return;
            }

            //Allow logged users which action has AllowAuthenticated attribute.
            if (actionAttributes.Where(x => x is AllowAuthenticated).Count() > 0)
            {
                return;
            }

            // Check menu permission.

            bool isRedirect = false;
            bool notFound   = false;

            foreach (var item in actionAttributes)
            {
                if (item is SubActionOf)
                {
                    var subActionOf = (SubActionOf)item;
                    (notFound, isRedirect, isAuthorized) = IsAuthorized(nccUser, moduleName, subActionOf.Controller, subActionOf.Action);
                    if (isAuthorized)
                    {
                        break;
                    }
                }
            }

            if (isAuthorized == false)
            {
                (notFound, isRedirect, isAuthorized) = IsAuthorized(nccUser, moduleName, action.ControllerName, action.ActionName);
            }


            if (notFound)
            {
                var url = action.ControllerName + "/" + action.ActionName;
                context.HttpContext.Items["ErrorMessage"] = $"URL '{url}' not found";
                context.HttpContext.Response.Redirect("/Home/ResourceNotFound");
                return;
            }

            if (isRedirect)
            {
                context.Result = new ChallengeResult(new AuthenticationProperties());
                context.HttpContext.Items["ErrorMessage"] = "You have not enough permission.";
                context.HttpContext.Response.Redirect("/Home/NotAuthorized");
                return;
            }

            if (isAuthorized == false)
            {
                context.Result = new ChallengeResult(new AuthenticationProperties());
                context.HttpContext.Items["ErrorMessage"] = "You do not have enought permission.";
                context.HttpContext.Response.Redirect("/Home/NotAuthorized");
            }
        }
Example #7
0
        public ActionResult CreateEdit(UserViewModel user, string SendEmail)
        {
            bool   isSuccess     = false;
            string returnMessage = "User Creation failed";

            if (user.Id > 0 && !string.IsNullOrEmpty(user.Email) && !string.IsNullOrEmpty(user.FullName) && !string.IsNullOrEmpty(user.Mobile))
            {
                var oldUser = _nccUserService.Get(user.Id);

                oldUser.FullName = user.FullName;
                oldUser.Email    = user.Email;
                oldUser.Mobile   = user.Mobile;

                oldUser.ExtraDenies.RemoveAll(x => x.ExtraDenyUserId == user.Id);
                oldUser.ExtraPermissions.RemoveAll(x => x.ExtraAllowUserId == user.Id);

                var allowedAdminMenuItems = user.AllowModules.Select(x => new { ModuleId = x.ModuleName, Items = x.AdminMenus.SelectMany(y => y.MenuItems.Where(z => z.IsChecked == true)) });

                var allowedWebSiteMenuItems = user.AllowModules.Select(x => new { ModuleId = x.ModuleName, Items = x.SiteMenus.SelectMany(y => y.MenuItems.Where(z => z.IsChecked == true)) }).ToList();

                foreach (var moduleMenu in allowedAdminMenuItems)
                {
                    foreach (var menuItem in moduleMenu.Items)
                    {
                        oldUser.ExtraPermissions.Add(new NccPermissionDetails()
                        {
                            Action           = menuItem.Action,
                            AllowUser        = oldUser,
                            Controller       = menuItem.Controller,
                            ExtraAllowUserId = oldUser.Id,
                            ModuleName       = moduleMenu.ModuleId
                        });
                    }
                }

                foreach (var moduleMenu in allowedWebSiteMenuItems)
                {
                    foreach (var menuItem in moduleMenu.Items)
                    {
                        oldUser.ExtraPermissions.Add(new NccPermissionDetails()
                        {
                            Action           = menuItem.Action,
                            AllowUser        = oldUser,
                            Controller       = menuItem.Controller,
                            ExtraAllowUserId = oldUser.Id,
                            ModuleName       = moduleMenu.ModuleId
                        });
                    }
                }

                var deniedAdminMenuItems = user.DenyModules.Select(x => new { ModuleId = x.ModuleName, Items = x.AdminMenus.SelectMany(y => y.MenuItems.Where(z => z.IsChecked == true)) });

                var deniedWebSiteMenuItems = user.DenyModules.Select(x => new { ModuleId = x.ModuleName, Items = x.SiteMenus.SelectMany(y => y.MenuItems.Where(z => z.IsChecked == true)) }).ToList();

                foreach (var moduleMenu in deniedAdminMenuItems)
                {
                    foreach (var menuItem in moduleMenu.Items)
                    {
                        oldUser.ExtraDenies.Add(new NccPermissionDetails()
                        {
                            Action          = menuItem.Action,
                            DenyUser        = oldUser,
                            Controller      = menuItem.Controller,
                            ExtraDenyUserId = oldUser.Id,
                            ModuleName      = moduleMenu.ModuleId
                        });
                    }
                }

                foreach (var moduleMenu in deniedWebSiteMenuItems)
                {
                    foreach (var menuItem in moduleMenu.Items)
                    {
                        oldUser.ExtraDenies.Add(new NccPermissionDetails()
                        {
                            Action          = menuItem.Action,
                            DenyUser        = oldUser,
                            Controller      = menuItem.Controller,
                            ExtraDenyUserId = oldUser.Id,
                            ModuleName      = moduleMenu.ModuleId
                        });
                    }
                }

                _nccUserService.Update(oldUser);

                if (user.IsSuperAdmin)
                {
                    NccUser userTemp = _userManager.FindByNameAsync(oldUser.UserName).Result;
                    var     result   = _userManager.AddToRoleAsync(userTemp, NccCmsRoles.SuperAdmin).Result;
                    if (result.Succeeded)
                    {
                        isSuccess     = true;
                        returnMessage = " User SuperAdmin Role update successful.";
                    }
                    else
                    {
                        isSuccess     = false;
                        returnMessage = result.Errors?.FirstOrDefault()?.Description;
                    }
                }
                else
                {
                    NccUser userTemp = _userManager.FindByNameAsync(oldUser.UserName).Result;
                    var     result   = _userManager.RemoveFromRoleAsync(userTemp, NccCmsRoles.SuperAdmin).Result;
                    if (result.Succeeded)
                    {
                        isSuccess     = true;
                        returnMessage = " User SuperAdmin Role remove successful.";
                    }
                    else
                    {
                        isSuccess     = false;
                        returnMessage = result.Errors?.FirstOrDefault()?.Description;
                    }
                }

                isSuccess = true;

                //return RedirectToAction("Index");
            }
            else if (ModelState.IsValid)
            {
                if (user.Password == user.ConfirmPassword)
                {
                    var nccUser = new NccUser()
                    {
                        Email = user.Email, FullName = user.FullName, UserName = user.UserName, Mobile = user.Mobile, Status = EntityStatus.Active
                    };
                    var result = _userManager.CreateAsync(nccUser, user.Password).Result;

                    var createdUser = _userManager.FindByNameAsync(user.UserName).Result;
                    if (createdUser != null)
                    {
                        if (user.IsSuperAdmin)
                        {
                            NccUser userTemp = _userManager.FindByNameAsync(createdUser.UserName).Result;
                            var     temp     = _userManager.AddToRoleAsync(userTemp, NccCmsRoles.SuperAdmin).Result;
                            isSuccess     = true;
                            returnMessage = "User created successfully.";
                        }
                        else
                        {
                            foreach (var item in user.Roles)
                            {
                                var permission = _nccPermissionService.Get(item);
                                createdUser.Permissions.Add(new NccUserPermission()
                                {
                                    Permission = permission, User = createdUser
                                });
                            }

                            createdUser.ExtraPermissions = GetSelectedPermissionDetails(user.AllowModules, createdUser, true);
                            createdUser.ExtraDenies      = GetSelectedPermissionDetails(user.DenyModules, createdUser, false);

                            var upResult = _userManager.UpdateAsync(createdUser).Result;
                            if (upResult.Succeeded == false)
                            {
                                returnMessage = "User role assign failed.";
                            }
                            else
                            {
                                isSuccess     = true;
                                returnMessage = "User created successfully.";
                            }
                        }
                    }
                }
                else
                {
                    returnMessage = "Password does not match.";
                }
            }
            else
            {
                returnMessage = "Please enter all required fields.";
                ModelState.AddModelError("", "Please enter all required fields.");
            }

            if (isSuccess)
            {
                ShowMessage(returnMessage, MessageType.Success, false, true);
                return(RedirectToAction("CreateEdit"));
            }

            var activeModules = GlobalContext.GetActiveModules();

            ViewBag.Modules = activeModules;
            var permissions = _nccPermissionService.LoadAll();

            ViewBag.Roles = new SelectList(permissions, "Id", "Name");

            ShowMessage(returnMessage, MessageType.Error);
            return(View("CreateEdit", user));
        }