Praveen Kumar

Praveen Kumar

  • NA
  • 235
  • 22.5k

How to change to static method to without static ?

Jun 9 2020 8:30 PM
Hi,
 
I want to remove static keyword from below method and some one help me ,if i remove what are all changes i need to do. 
 
 
 Helperclass.cs
 
public static SelectList CompaniesByUser(int customerId, User user, bool addBlankOption = false)
{
DbContextScopeFactory DbContext = new DbContextScopeFactory(new Redi2ContextFactory(new LoginSecurityRepo().GetRMApplConnection()));
AmbientDbContextLocator ambientContextLocator = new AmbientDbContextLocator();
var repo = new CompanyRepository(ambientContextLocator);
using (var ctx = DbContext.CreateReadOnly())
{
var companies = repo.GetCompaniesByUser(user, customerId);
if (addBlankOption)
companies.Insert(0, new Organization { Id = 0, Name = "<select company>" });
return new SelectList(companies.Select(c => new { c.Id, Name = string.IsNullOrEmpty(c.OrganizationNumber) ? c.Name : $"{c.Name} | {c.OrganizationNumber}" }), "Id", "Name");
}
}
 
 Controller
 
SelectList companyList = SelectListItemHelper.CompaniesByUser(customerId,user,true);
 
BillingViewModel model = new BillingViewModel()
{
Companies = SelectListItemHelper.CompaniesByUser(customerId,user,true),
};
return View(model);
 
 

Answers (2)