Ejemplo n.º 1
0
        // GET: api/Roles/5
        public RoleCustom Get(int id)
        {
            var        roleEntity = unitOfWork.RolesManager.GetByID(id);
            RoleCustom role       = new RoleCustom();

            role.id       = roleEntity.id;
            role.RuleName = roleEntity.RuleName;
            role.status   = roleEntity.status;
            return(role);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddAndEditRole(RoleCustom data)
        {
            #region Authorization code
            var    identity = HttpContext.User.Identity as ClaimsIdentity;
            string id       = "";
            string role     = "";
            if (identity != null)
            {
                IEnumerable <Claim> claims = identity.Claims;
                // or
                id   = identity.Claims.Where(m => m.Type == ClaimTypes.Sid).Select(m => m.Value).FirstOrDefault();
                role = identity.Claims.Where(m => m.Type == ClaimTypes.Role).Select(m => m.Value).FirstOrDefault();
            }
            long userId = Convert.ToInt32(id);
            #endregion
            //calling RoleDAL busines layer
            CommonResponse response = new CommonResponse();
            response = roleMaster.AddAndEditRole(data, userId);

            return(Ok(response));
        }
Ejemplo n.º 3
0
        public ActionResult AddRole(RoleCustom role)
        {
            try
            {
                if (role == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                var roleName = role.RoleName.Trim();

                if (roleName == "")
                {
                    throw new Exception("No RoleName");
                }

                // Create Role
                var roleManager =
                    new RoleManager <IdentityRole>
                    (
                        new RoleStore <IdentityRole>(new ApplicationDbContext())
                    );

                if (!roleManager.RoleExists(roleName))
                {
                    roleManager.Create(new IdentityRole(roleName));
                }

                return(Redirect("~/Admin/ManageRole").WithSuccess("Role added successfully!"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, @"Error: " + ex.Message);
                return(View("AddRole"));
            }
        }
Ejemplo n.º 4
0
        public ActionResult AddRole()
        {
            var objRole = new RoleCustom();

            return(View(objRole));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add and Edit Document
        /// </summary>
        /// <param name="data"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public CommonResponse AddAndEditRole(RoleCustom data, long userId = 0)
        {
            CommonResponse obj = new CommonResponse();

            try
            {
                var res = db.RoleMaster.Where(m => m.RoleId == data.roleId).FirstOrDefault();
                if (res == null)
                {
                    try
                    {
                        RoleMaster item = new RoleMaster();
                        item.RoleName        = data.roleName;
                        item.RoleDescription = data.roleDescription;
                        item.IsActive        = true;
                        item.IsDeleted       = false;
                        item.CreatedBy       = userId;
                        item.CreatedOn       = DateTime.Now;
                        db.RoleMaster.Add(item);
                        db.SaveChanges();
                        obj.response = ResourceResponse.AddedSucessfully;
                        obj.isStatus = true;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex); if (ex.InnerException != null)
                        {
                            log.Error(ex.InnerException.ToString());
                        }
                        obj.response = ResourceResponse.ExceptionMessage;
                        obj.isStatus = false;
                    }
                }
                else
                {
                    try
                    {
                        res.RoleName        = data.roleName;
                        res.RoleDescription = data.roleDescription;
                        res.ModifiedBy      = userId;
                        res.ModifiedOn      = DateTime.Now;
                        db.SaveChanges();
                        obj.response = ResourceResponse.UpdatedSucessfully;
                        obj.isStatus = true;
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex); if (ex.InnerException != null)
                        {
                            log.Error(ex.InnerException.ToString());
                        }
                        obj.response = ResourceResponse.ExceptionMessage;
                        obj.isStatus = false;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex); if (ex.InnerException != null)
                {
                    log.Error(ex.InnerException.ToString());
                }
                obj.response = ResourceResponse.ExceptionMessage;
                obj.isStatus = false;
            }
            return(obj);
        }