Printing Directly from Asp.Net MVC Controller Action to Printer in the Network

public async Task<ActionResult> Generate(string id)
{
     PrintDocument pd = new PrintDocument();
     pd.DefaultPageSettings.Margins.Left = 30;
     pd.DefaultPageSettings.Margins.Top = 10;
     pd.DefaultPageSettings.Margins.Right = 10;
     pd.DefaultPageSettings.Margins.Bottom = 10;
     pd.OriginAtMargins = true;
     pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
     // Set the printer name.
     //pd.PrinterSettings.PrinterName = "\\NS5\hpoffice
     //pd.PrinterSettings.PrinterName = "HP LaserJet 200 color M251 PCL6 Class Driver";
     pd.PrinterSettings.PrinterName = "EPSON LX-310";
     pd.Print();

     return RedirectToAction("Index", "Payslip", new { area = "Accounting", id = "", code = 801 });
}

void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
     Font printFont = new Font("3 of 9 Barcode", 18);
     Font printFont1 = new Font("Times New Roman", 11, FontStyle.Bold);
     SolidBrush br = new SolidBrush(Color.Black);
     ev.Graphics.DrawString("hello", printFont, br, 10, 65);
     ev.Graphics.DrawString("world", printFont1, br, 10, 85);
}

Loosely Coupled , Test Driven Design and API Centric Application

I now have my Asp.net MVC WebAPI 2 implemented with Test Driven Design.

Loosely Coupled with the help of Unity and TDDed with Moq.

Now I can begin porting my Real Estate Billing Management System coded in PHP and Zend Framework

public class PeopleRepository<T> : IPeopleRepository<T> where T : class
{
   protected AppDBContext db;

   public PeopleRepository(IUnitOfWork unitOfWork)
   {
     db = unitOfWork.DbContext;
   }
}
   public interface IPeopleRepository<T> where T : class
   {
      IEnumerable<T> FindAll();
      T GetByID(int id);
      void Delete(int id);
      void SaveOrUpdate(T customer);
   }
   public interface IPeopleRepository<T> where T : class
   {
      IEnumerable<T> FindAll();
      T GetByID(int id);
      void Delete(int id);
      void SaveOrUpdate(T customer);
   }

I will have this Application front ended with AngularJs2 because of TypeScript.

I heard that ReactJs is becoming more popular. But just *7^&off!

Asp.Net Identity IsInRole not working or Returning Empty

Hi Kids,

If this piece of code in Asp.Net MVC 5 on .Net 4.6 is Not working

User.IsInRole("Admin");

Just code it like this.

       ApplicationUser u = await UserManager.FindByNameAsync(username);
       var roles = u.Roles;
       List<string> s = new List<string>();
       foreach (var i in roles)
       {
           var r = db.Roles.SingleOrDefault(w => w.Id == i.RoleId);
           s.Add(r.Name);                        
       }

       if (s.Contains("Admin"))
       {
          return RedirectToAction("Index","Jumpers");
       }

It will save you time.

Alright Kids! You’re Welcome!