Posts

Showing posts from 2019

Linq Compare to a list

Establish your list var idList = new [] {5, 7}; Compare against the List var jobs = originaljobs.Where(t => t.StatusId != null).Where(t => idList .Contains((int)t.StatusId));  

Conversion Classes

Convert from Model to Dataset public static DataSet ToDataSet (this IList list) { Type elementType = typeof(T); DataSet ds = new DataSet(); DataTable t = new DataTable(); ds.Tables.Add(t); //add a column to table for each public property on T foreach (var propInfo in elementType.GetProperties()) { Type ColType = Nullable.GetUnderlyingType(propInfo.PropertyType) ?? propInfo.PropertyType; t.Columns.Add(propInfo.Name, ColType); } //go through each property on T and add each value to the table foreach (T item in list) { DataRow row = t.NewRow(); foreach (var propInfo in elementType.GetProperties()) { row[propInfo.Name] = propInfo.GetValue(item, null) ?? DBNull.Value; } t.Rows.Add(row);

Jquery ... little things

Code Snippets Remove duplicate IDs on a page - but not the first one     $('[id]').each(function () {                          $('[id="' + this.id + '"]:gt(0)').remove();                       });

Open XML and Word Doc creation

https://github.com/OfficeDev/office-content/blob/master/en-us/OpenXMLCon/articles/360318b5-9d17-42a1-b707-c3ccd1a89c97.md While at Lockheed I created an interface that modified and created contracts on the fly - wish I had kept some code references  - but I started here To generate Word documents with Office Automation within .NET, specifically in C# or VB.NET: Add the  Microsoft.Office.Interop.Word  assembly reference to your project. The path is  \Visual Studio Tools for Office\PIA\Office11\Microsoft.Office.Interop.Word.dll . Follow the Microsoft code example you can find here:  http://support.microsoft.com/kb/316384/en-us .

API Examples Returning various ...

API Examples  public IQueryable<Customer> GetCustomers()         {             return db.Customers;     [ResponseType(typeof(Customer))]         public IHttpActionResult GetCustomer(string email)         {             Customer customer = db.Customers.Where(c=>c.Email== email).FirstOrDefault();             if (customer == null)             {                 return NotFound();             }             return Ok(customer);         }     }   // PUT: api/Customers/5         [ResponseType(typeof(void))]         public IHttpActionResult PutCustomer(int id, Customer customer)         {             if (!ModelState.IsValid)             {                 return BadRequest(ModelState);             }             if (id != customer.Id)             {                 return BadRequest();             }             db.Entry(customer).State = EntityState.Modified;             try             {                 db.SaveChanges();             }             c

Security

using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; using System.Web; namespace LM_API {     public static class SiteMethods     {         public static string ComputeHash(string plainText,                                     string hashAlgorithm,                                     byte[] saltBytes)         {  // If salt is not specified, generate it on the fly.             if (saltBytes == null)             {                 // Define min and max salt sizes.                 int minSaltSize = 4;                 int maxSaltSize = 8;                 // Generate a random number for the size of the salt.                 Random random = new Random();                 int saltSize = random.Next(minSaltSize, maxSaltSize);                 //Hardcoded the salt size                 //  int saltSize = 3;                 // Allocate a byte array, which will hold the salt.                 saltBytes = ne

Return View of a model or an HttpStatusCode

        public ActionResult Details(int? id)         {             if (id == null)             {                 return new HttpStatusCodeResult(HttpStatusCode.BadRequest);             }                     OrderNote orderNote = mymethodtoretriverecord(id);             if (orderNote == null)             {                 return HttpNotFound();             }             return View(orderNote);         }        

Pseudo Class when you need a generic object

        public class PseudoProduct : calldetail_viw        {        }; public List<calldetail_viw> GetTeamMonthlySummary()        {                    int currentmonth = DateTime.Today.Month;            int lastmonth = DateTime.Today.AddMonths(-3).Month;            var calldata = (from c in db.calldetail_viw                where c.ConnectedDate.Value.Month >= lastmonth                      && c.ConnectedDate.Value.Month <= currentmonth                      && c.LocalName == "myaccountrep"                      && c.CallDirection=="Inbound"                group c by new {c.AssignedWorkGroup, month = c.ConnectedDate.Value.Month}                into g                select new PseudoProduct                {                    AssignedWorkGroup = g.Key.AssignedWorkGroup,                    CustomNum1 = g.Key.month,                    CustomNum2 = g.Count()                });                  var cl = new List&l

HTML Helper Methods

public static class CoverageAuthorization     {         public static MvcHtmlString ShowHideLink( this HtmlHelper helper,string linkSupplied, string username)         {                     var approvalHierarchy = ConfigurationManager.AppSettings["ApprovalHierarchy"];             approvalHierarchy = approvalHierarchy.Substring(approvalHierarchy.IndexOf("Supervisor"));             var claimManager = new ClaimManager();             var currentUser = claimManager.GetClaimUserByLogin(username);             if (approvalHierarchy.IndexOf(currentUser.Role.ToString()) >= 0)             {                               return MvcHtmlString.Create("<br />" + linkSupplied);             }             else             {                 return MvcHtmlString.Empty; ;             }         }     } To use it  @Html.ShowHideLink("<a href='/CaseLoadTransition/Index'>Case Load Transition</a> ", HttpContext.Current.Us

Export Grid to Excel with JQuery

Using Table2Excel Grab the Javascript Table2Excel and make sure you have a reference to a recent Jquery library https://rawgit.com/unconditional/jquery-table2excel/master/src/jquery.table2excel.js Create a button click or other event $("#myButton").click(function(){  $("#myGridorTable").table2excel({             exclude: ".noExl",             name: "MyExcel.xls"         }); }; There you go - button click - excel returned as a file to the browser.

Soap call from Controller

public static void Execute(string NTID)         {             HttpWebRequest request = CreateWebRequest();             XmlDocument soapEnvelopeXml = new XmlDocument();             soapEnvelopeXml.LoadXml(@"<?xml version=""1.0"" encoding=""utf-8""?>                <soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""                          xmlns:urn=""urn:sap-com:document:sap:rfc:functions"">                 <soapenv:Header xmlns:wsa =""http://www.w3.org/2005/08/addressing"" >                    <wsa:Action>urn:sap-com:document:sap:rfc:functions:Z_WS_TRAIN_HIST:Z_GET_TRAIN_HISTRequest                         </wsa:Action></soapenv:Header>                 <soapenv:Body>                     <urn:Z_GET_TRAIN_HIST >                      <IM_TBL_TRAIN_HIST_INPUT>                       <item>

Favorite Powershell Scripts

Mock sitemap This simple script gives us an overview of all pages - we just need to clean up the bin and obj folder listings  - do some simple replaces and turn it into links or a sitemap It creates a list of all of the filetypes specified into an output text file Below I have specified on .aspx files but you could do something like .htm,asp,aspx instead to include multiple file types. Get-ChildItem D:\mydirectory\My.WebApplication -recurse -include *.aspx| ForEach-Object { $_.FullName } > D:\mydirectory\My.WebApplication\output.txt More Powershell Resources PowerShell Scripts Repository Stackify Power Shell Commands Cheatsheet