private void SaveAddedPin(HttpContext context) { int board = int.Parse(context.Request.Params["board"]); string desc = context.Request.Params["desc"]; string img = context.Request.Params["img"]; string destRel = Common.UploadedImageRelPath + Common.UserID; string dest = Common.UploadedImagePath + Common.UserID; string destFileName = Guid.NewGuid().ToString() + ".jpg"; string destFileFullPath = Path.Combine(dest, destFileName); WebClient client = new WebClient(); MemoryStream ms = new MemoryStream(client.DownloadData(img)); using (Image image = Image.FromStream(ms)) { if (!Directory.Exists(dest)) { Directory.CreateDirectory(dest); } image.Save(destFileFullPath, ImageFormat.Jpeg); } string relPath = Common.UserID + "/" + destFileName; byte[] _d = File.ReadAllBytes(destFileFullPath); ulong _crc64; ulong _murmur2; ulong _fnv1a; short height, width; CalcHash(_d, out _crc64, out _murmur2, out _fnv1a, out height, out width); using (TransactionScope scope = new TransactionScope()) { try { Nails.edmx.Images i = new Nails.edmx.Images(); i.CRC64 = _crc64; i.MURMUR2 = _murmur2; i.Tagged = true; i.FNV1a = _fnv1a; i.Image_Height = height; i.Image_Width = width; i.Uploaded = true; i.RelativeImage_Path = relPath; Nails.edmx.NailsProdEntities _context = this.GetNailsProdContext; _context.Images.AddObject(i); _context.SaveChanges(); Nails.edmx.BoardsImagesMapping bim = new Nails.edmx.BoardsImagesMapping(); bim.BoardID = board; bim.ImageID = i.ID; bim.Image_Title = desc; bim.Source = img; bim.UserID = Common.UserID.Value; _context.BoardsImagesMapping.AddObject(bim); _context.SaveChanges(); scope.Complete(); context.Response.Write(JsonConvert.SerializeObject(new { PinID = (_crc64 + (ulong)bim.ID).ToString() })); } catch (Exception e) { throw; } finally { scope.Dispose(); } } }