public bool RemovePermission(operationPermission obj)
        {
            var role = (from operationPermission in _context.OperationPermissions
                        where operationPermission.OperationID == obj.OperationID && operationPermission.RoleId == obj.RoleId
                        select operationPermission).FirstOrDefault();

            if (role != null)
            {
                _context.OperationPermissions.Remove(role);
                var result = _context.SaveChanges();

                if (result > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        public bool CheckPermissionExists(operationPermission obj)
        {
            var result = (from operationPermission in _context.OperationPermissions
                          where operationPermission.OperationID == obj.OperationID && operationPermission.RoleId == obj.RoleId
                          select operationPermission).Count();

            return(result > 0 ? true : false);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="operationType"></param>
        public transportSettings(operationPermission operationType, string modemName, string headertext)
        {
            this.operationPerissions = operationType;

            InitializeComponent();
            this.initialiseInputControls();
            this.lblHeader.Text = headertext;
            this.instOldValues  = this.loadTransportDetails(modemName);
        }
        public bool AddPermission(operationPermission obj)
        {
            _context.Add(obj);
            var result = _context.SaveChanges();

            if (result > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public async Task <IActionResult> Post([FromBody] operationPermission operationPermission)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_operationPermissionRepository.CheckPermissionExists(operationPermission))
                    {
                        var response = new HttpResponseMessage()
                        {
                            StatusCode = HttpStatusCode.Conflict
                        };

                        return(BadRequest("Role Already Exists"));
                    }
                    else
                    {
                        operationPermission.OperationPermissionID = 0;
                        _operationPermissionRepository.AddPermission(operationPermission);

                        var response = new HttpResponseMessage()
                        {
                            StatusCode = HttpStatusCode.OK
                        };

                        // return response;
                        return(Ok());
                    }
                }
                else
                {
                    var response = new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.BadRequest
                    };

                    //return response;
                    return(BadRequest());
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
 public async Task <IActionResult> DeletePermission([FromBody] operationPermission operationPermission)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Boolean result = _operationPermissionRepository.RemovePermission(operationPermission);
             if (result)
             {
                 return(Ok());
             }
             return(BadRequest("Not Deleted Record"));
         }
         catch (Exception ex)
         {
             return(BadRequest(ex.Message));
         }
     }
     else
     {
         return(BadRequest());
     }
 }