Why Juery post method converts into get method ?

Why Juery post method converts into get method ?

I have a jquery method with post method, and it is working fine in my local machine. 

But when I uploaded on window IIS server and tried to run it was not working. I checked in "Network" tab using inspect element, it was calling "get" method instead of "post"

Issue


function fnConfirm(model) {
    $('#myModalDelete').modal('show');
    $("#DeleteDiv").html("Are you sure you want to delete this record?");
    $("#ConfirmDeleting").click(function () {
        $.ajax({
            url: "Controller/DeleteData/" + model.id,
            type: 'post',
            contentType: 'application/x-www-form-urlencoded',
            data: $(this).serialize(),
            success: function (data, textStatus, jQxhr) {
                $('#myModalDelete').modal('hide');
                table.ajax.reload(null, false);
            },
            error: function (jqXhr, textStatus, errorThrown) {
                console.log(errorThrown);
            }
        });
    });
}
  

Solution

I have changed two things,

1. set URL in lowercase
2. set type in uppercase


function fnConfirm(model) {
    $('#myModalDelete').modal('show');
    $("#DeleteDiv").html("Are you sure you want to delete this record?");
    $("#ConfirmDeleting").click(function () {
        $.ajax({
            url: "headerlinks/deletedata/" + model.id,
            type: 'POST',
            contentType: 'application/x-www-form-urlencoded',
            data: $(this).serialize(),
            success: function (data, textStatus, jQxhr) {
                $('#myModalDelete').modal('hide');
                table.ajax.reload(null, false);
            },
            error: function (jqXhr, textStatus, errorThrown) {
                console.log(errorThrown);
            }
        });
    });
}
  
Now, its working fine in Live server as well as in local machine.


Hope this will help you and save your time.

Enjoy !!!

:)

Mock Unit Testing with Example

Mock Unit Testing with Example


Unit test cases should implement in our project, so as a developer we can assure that developed feature is working fine.

Here I have created a sample end to end.

DB Layer

//DB Layer: Database Class
public class tblUser
{
 public virtual string AddUser()
 {
  throw new NotImplementedException();
  //return "success";
 }
}
  

Business Layer

//Business Layer : Service Class
public class BLUser
{
 private readonly tblUser _BLUser;
 public BLUser(tblUser bLUser)
 {
  _BLUser = bLUser;
 }

 public string AddUser()
 {
  return _BLUser.AddUser();
 }
}
  

Implementation Layer

//Implementation Layer 
public class UserUI
{
 public string AddNew()
 {
  BLUser user = new BLUser(new tblUser());

  return user.AddUser();
 }
}
  

Test Project

//Unit Test: Test Class
[TestClass]
public class BLUserTest
{
 [TestMethod]
 public void AddUserTest()
 {
  var mockBLUser = new Mock<tblUser>();
  mockBLUser.Setup(mk => mk.AddUser()).Returns("success");
  var user = new BLUser(mockBLUser.Object);
  var actual = user.AddUser();
  Assert.AreEqual("success", actual);
 }  
}
   

Now you can do process on fileContent as per your requirement.

Hope this will help you and save your time.

Enjoy !!!

:)

How to add file in Resource file in C# ?

How to add file in Resource file in C# ?


We can add text or xml file in resource file in c# class library project.

Steps, how to use it.

 

Steps


1. Right click on project and select properties
2. Click on Resources option from left side
3. Click on link available in middle of the section, link as "This project does not contain a default resource file. Click here to create one."
4. Click on "Add Resource" from section menu and select "Add Existing File"
5. Select file from your file path
6. File is added in resource file
7. You can rename file name as per your requirement
  

Code

How to use file content in C# program

Add namespace 

using projectNameSpace.Properties;

byte[] file = Resources.FileName;
Stream stream = new MemoryStream(file);
string fileContent = "";

using (StreamReader reader = new StreamReader(stream))
{
     fileContent = reader.ReadToEnd();
}
  
Now you can do process on fileContent as per your requirement.


Hope this will help you and save your time.

Enjoy !!!

:)

Error: Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'

Error: Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'


Issue

Message=Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility of the base type or be less accessible.

Source=Microsoft.Rest.ClientRuntime

Solution


I have updated nuget package "System.Net.Http" to version 4.3.1 with NuGet and that solved the issue.
  
Hope this will help you and save your time.

Enjoy !!!

:)

Explicit construction of entity type '###' in query is not allowed.

Explicit construction of entity type '###' in query is not allowed.


Issue

Explicit construction of entity type '###' in query is not allowed.

Solution


var result = from ev in db.Events
 join ea in db.EventAttendees on ev.EventId equals ea.EventId
 where ea.UserId == userid
 select new VMEvent // Here Don't use actual entity class name, Create new view model class
 {
  EventName = ev.EventName,
  EventAttendeeSubmittedDate = ea.SubmittedDate.ToString(),
  Place = ev.Place, 
  EventAttendeeNoofMembers = ea.noofMembers.ToString() 
  }; 

var arrayResult = result.ToArray();
var listResult = result.ToList();
 
  
Hope this will help you and save your time.

Enjoy !!!

:)

Unable to load one or more breakpoints in Visual Studio

Unable to load one or more breakpoints in Visual Studio


Issue

While I am opening the project, I got the error messag box "Unable to load one or more breakpoints".

Solution


I have resolved this issue by deleting the .vs directory and reopen visual stuio then the project.
  
Hope this will help you and save your time.

Enjoy !!!

:)

MongoDB with Credential in C#

MongoDB with Credential in C#




Open command prompt and goto C:\Program Files\MongoDB\Server\4.1\bin>


1.mongod --port 12345

2.mongo --port 12345

3.use admin;

4.db.createUser(
  {
    user: "admin",
    pwd: "admin143#",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
  }
);

5.Restart mongodb instance

6.mongod --auth --port 12345

7.mongo --port 12345 -u "admin" -p "admin143#" --authenticationDatabase "admin"

8.use dbname

9.db.createUser(
  {
    user: "User1",
    pwd: "User1143#",
    roles: [ { role: "readWrite", db: "dbname" },
             { role: "read", db: "reporting" } ]
  }
);

Restart mongodb instance

10.  Install MongoDB Service
 mongod.exe --config "D:\MongoDB\demodb.conf" --service --install --serviceName "MongoDB DemoDB 12345" --serviceDisplayName "MongoDB DemoDB 12345" --auth 
 

 mongoDB usage with C# with credential

Sample code


//Create instance 
MongoUrl url = new MongoUrl("mongodb://username:password@hostname:port/demo");
MongoClient client = new MongoClient(url);
 
//Get Database 
var database = client.GetDatabase(url.DatabaseName);
 
//Read collection
IMongoCollection<Users> tempCollection  = database.GetCollection<classname>("collectionname");
 
//Result data
List<classname> resultData = tempCollection.AsQueryable().Where<classname>(a => a.propertyname == value).ToList();
 
  
Hope this will help you and save your time.

Enjoy !!!

:)