Пример #1
0
    /// <summary>
    /// Checks whether the logged user has the givin permission.
    /// </summary>
    /// <param name="permission"></param>
    /// <returns></returns>
    /// <author>Saad Mansour</author>
    public static bool IsLoggedUserHasPermission(GeneralEnums.Permissions permission)
    {
        bool isLoggedUserInRole = false;

        try
        {
            string loggedUserName = HttpContext.Current.User.Identity.Name.ToUpper();
            int userRoleID = User_Credential.GetRoleIdByUserName(loggedUserName);

            using (GRASPEntities db = new GRASPEntities())
            {
                var permissionName = from p in db.Permissions
                    join rp in db.RolePermissions on p.id equals rp.PermissionID
                    where rp.RoleID == userRoleID
                    select p.Name;

                if (permissionName.Contains(permission.ToString()))
                {
                    isLoggedUserInRole = true;
                }
            }
        }
        catch (Exception ex)
        {
            LogUtils.WriteErrorLog(ex.ToString());
        }

        return isLoggedUserInRole;
    }
Пример #2
0
 /// <summary>
 /// Deletes the file from the given ResponseFiles folder.
 /// </summary>
 /// <param name="folderName"></param>
 /// <author>Saad Mansour</author>
 private void DeleteFormFromResponseFileFolder(string fileName, GeneralEnums.ResponseFilesFolderNames folderName)
 {
     try
     {
         if (fileName.Length > 0)
         {
             File.Delete(Utility.GetResponseFilesFolderName() + folderName.ToString() + "\\" + fileName);
         }
     }
     catch (Exception ex)
     {
         LogUtils.WriteErrorLog(ex.ToString());
     }
 }
Пример #3
0
    /// <summary>
    /// Saves the given file in the given folder name.
    /// </summary>
    /// <param name="data"></param>
    /// <param name="fileName"></param>
    /// <param name="folderName"></param>
    /// <author>Saad Mansour</author>
    public void SaveFileInResponseFilesFolder(string data, string fileName, GeneralEnums.ResponseFilesFolderNames folderName)
    {
        try
        {
            string folderPath = Utility.GetResponseFilesFolderName() + folderName.ToString() + "\\";

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }
            using (StreamWriter file = new StreamWriter(folderPath + fileName, false))
            {
                file.Write(data);
                file.Close();
            }
        }
        catch (Exception ex)
        {
            LogUtils.WriteErrorLog(ex.ToString());
        }
    }