Posts

Showing posts from April, 2016

Saving Base64 String as image to Azure Blob Storage

  Recently I started working on a API which supports mobile backend. I got the following requirement 1. When user uploads a image to their profile API will get the base64 string of the image 2. When viewing the User profile to increase the performance of service calls have to send an image URL rather base64 string   Solution : Save the base 64 string in the azure storage & save it in DB public class AzureBlogService { private static string _connectionString = "DefaultEndpointsProtocol=https;AccountName=****;AccountKey=****"; public static string UploadImage(string imageData, ImageType imageType, int cardId) { string filename = GetFileName(imageType, cardId); CloudBlobContainer container = GetContainer("userimages"); byte[] imageBytes = Convert.FromBase64String(imageData); CloudBlockBlob blob = container.GetBlockBlobReference(filename); blob.Properties.Cont

Group By First Letter of word with Linq

  This is sample code which you can used to group some list of objects based on first letter of the object name or any string property. In the following example I get list of contacts in an application and after getting those from DB , I group them with the First letter of the Contact name and order them in alphabetical order. Following is my Contact Class. public class CardContactModel { public int CardId { get; set; } public string CardName { get; set; } public int? ContactId { get; set; } public JObject Information { get; set; } public string ProfileImage { get; set; } public string SharedTo { get; set; } public string RecievedFrom { get; set; } } Then I group it and add it to a dictionary with the following line of code. Dictionary > Contacts = contacts.GroupBy(x => x.CardName.Substring(0, 1).ToUpper(), (Letter, Contacts) => new { Alphabet = Letter, SubList = Contacts.OrderBy(