public IActionResult Add([FromRoute] long fileId, [FromBody] FileBlockInfo fileBlockInfo) { FileBlock fileBlock = _db.FileBlocks.FirstOrDefault(fb => fb.FileId == fileId && fb.Number == fileBlockInfo.Number); using (MD5 md5Hash = MD5.Create()) { byte[] rawContent = Convert.FromBase64String(fileBlockInfo.Value); if (fileBlock == null) //Create new fileBlock { _db.FileBlocks.Add(new FileBlock() { FileId = fileId, Number = fileBlockInfo.Number, Content = rawContent, Checksum = MD5Utils.GetMd5Hash(md5Hash, rawContent.ToString()) }); } else //Update existing fileBlock { fileBlock.Content = rawContent; fileBlock.Checksum = MD5Utils.GetMd5Hash(md5Hash, rawContent.ToString()); _db.FileBlocks.Update(fileBlock); } _db.SaveChanges(); } return(StatusCode((int)HttpStatusCode.OK)); }
public static MvcHtmlString Gravatar( this HtmlHelper htmlHelper, string email, int size = 80, string defaultImage = "mm", object htmlAttributes = null) { var img = new TagBuilder("img"); if (htmlAttributes != null) { // Get the attributes IDictionary <string, object> attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); // set the attributes img.MergeAttributes(attributes); } img.AddCssClass("gravatar"); var hash = MD5Utils.GetMd5Hash(email.ToLower()); var encodedSize = htmlHelper.Encode(size); var encodedDefaultImage = htmlHelper.Encode(defaultImage); var url = $"//gravatar.com/avatar/{hash}.jpg?s={encodedSize}&d={encodedDefaultImage}"; img.MergeAttribute("src", url); return(MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing))); }
public static string GetMd5Hash(string str) { using (System.Security.Cryptography.MD5 md5hash = System.Security.Cryptography.MD5.Create()) { string hashstr = MD5Utils.GetMd5Hash(md5hash, str); return(hashstr); } }