Ejemplo n.º 1
0
        // TO POST AN IMG YOU NEED THE HttpPosted //
        public bool CreateArt(HttpPostedFileBase file, ArtCreate model)
        {
            // This piece of code calls a method that converts your img into Bytes //
            model.ImageContent = ConvertToBytes(file);

            var entity =
                new Art()
            {
                OwnerID        = _userId,
                Title          = model.Title,
                Style          = model.Style,
                Medium         = model.Medium,
                Surface        = model.Surface,
                Size           = model.Size,
                Price          = model.Price,
                Location       = model.Location,
                Sold           = model.Sold,
                DateOfCreation = model.DateOfCreation,
                Note           = model.Note,
                ImageContent   = model.ImageContent
                                 //ImageContent = bytes
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Arts.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 2
0
        public ActionResult Create(ArtCreate model)
        {
            HttpPostedFileBase file = Request.Files["ImageData"];

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateArtService();

            if (service.CreateArt(file, model))
            {
                TempData["SaveResult"] = "Your Art was added to your inventory.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Art could not be added.");
            return(View(model));
        }