public ActionResult Edit(Drawing newDrawing, HttpPostedFileBase drawingImageFile, string canvasImage)
 {
     if (ModelState.IsValid)
     {
         Drawing drawing = m_drawingsService.Get(newDrawing.Id);
         drawing = FillDrawing(drawing, drawingImageFile, canvasImage);
         if (drawing != null)
         {
             m_drawingsService.Update(drawing);
             return RedirectToAction("Index");
         }
     }
     return View(newDrawing);
 }
 private Drawing FillDrawing(Drawing newDraw, HttpPostedFileBase drawingImage, string canvasImage)
 {
     TryUpdateModel(newDraw);
     if (ModelState.IsValid)
     {
         if (drawingImage != null)
         {
             newDraw.ImageContentType = drawingImage.ContentType;
             newDraw.Image = new byte[drawingImage.ContentLength];
             drawingImage.InputStream.Read(newDraw.Image, 0, drawingImage.ContentLength);
             return newDraw;
         }
         else if (canvasImage != null)
         {
             Regex expr = new Regex("data:(.*);base64,(.*)");
             MatchCollection matches = expr.Matches(canvasImage);
             if (matches.Count == 1 && matches[0].Groups.Count == 3)
             {
                 // first group in match is the whole text
                 newDraw.ImageContentType = matches[0].Groups[1].Value;
                 newDraw.Image = Convert.FromBase64String(matches[0].Groups[2].Value);
             return newDraw;
             }
         }
     }
     return null;
 }