public void InsertOrUpdate(Player player)
 {
     if (player.Id == default(Guid)) {
         // New entity
         player.Id = Guid.NewGuid();
         context.Players.Add(player);
     } else {
         // Existing entity
         context.Entry(player).State = EntityState.Modified;
     }
 }
 public ActionResult Edit(Player player)
 {
     if (ModelState.IsValid) {
         AddPostedFiles(player);
         playerRepository.InsertOrUpdate(player);
         playerRepository.Save();
         return RedirectToAction("Index");
     } else {
         ViewBag.States = this.stateRepository.GetStates();
         return View();
     }
 }
        private void AddPostedFiles(Player player)
        {
            if (Request.Files.Count == 0)
            {
                return;
            }

            // assume only 1 file posted
            HttpPostedFileBase hpf = Request.Files[0] as HttpPostedFileBase;

            if (hpf.ContentLength == 0)
                return;
            string extension = Path.GetExtension(hpf.FileName);
            string newFileName = Guid.NewGuid().ToString() + extension;

            var blob = this.blobAgent.GetContainer().GetBlobReference(newFileName);
            blob.Properties.ContentType = BlobAgent.GetContentTypeFromExtension(extension);
            blob.UploadFromStream(hpf.InputStream);
            player.PhotoUri = blob.Uri.AbsolutePath;

            //string serverFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "roster-images", newFileName);
            //hpf.SaveAs(serverFileName);
            //player.PhotoUri = "/roster-images/" + newFileName;
        }