コード例 #1
0
        // GET
        public ActionResult DeletePicture(int id, int idtournoi)
        {
            TournamentPicture image = db.TournamentPictures.Find(id);

            db.TournamentPictures.Remove(image);
            db.Entry(image).State = EntityState.Deleted;
            db.SaveChanges();
            // return Json(image);
            return(RedirectToAction("edit", "tournaments", new { id = idtournoi }));
        }
コード例 #2
0
ファイル: ArcheryHelpers.cs プロジェクト: anneprt/Archery
        public static MvcHtmlString PictureTournament(this HtmlHelper helper, TournamentPicture picture, string cssClass = "")
        {
            var image  = new TagBuilder("img");
            var base64 = Convert.ToBase64String(picture.Content);
            var src    = $"data:{picture.ContentType};base64,{base64}";

            image.Attributes.Add("src", src);
            image.Attributes.Add("alt", picture.Name);
            if (!string.IsNullOrWhiteSpace(cssClass))
            {
                image.Attributes.Add("class", cssClass);
            }
            return(MvcHtmlString.Create(image.ToString()));
        }
コード例 #3
0
 public ActionResult AddPicture(HttpPostedFileBase picture, int id)
 {
     if (picture?.ContentLength > 0)
     {
         var tp = new TournamentPicture();
         tp.ContentType  = picture.ContentType;
         tp.Name         = picture.FileName;
         tp.TournamentID = id;
         using (var reader = new BinaryReader(picture.InputStream))
         {
             tp.Content = reader.ReadBytes(picture.ContentLength);
         }
         db.TournamentPictures.Add(tp);
         db.SaveChanges();
         return(RedirectToAction("edit", "tournaments", new { id = id }));
     }
     return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
 }