public async Task <IActionResult> Edit(int id, [Bind("PicID,StoragePath")] pictures pictures)
        {
            if (id != pictures.PicID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(pictures);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!picturesExists(pictures.PicID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(pictures));
        }
Esempio n. 2
0
        public ActionResult Add(pictures image, string post, string description)
        {
            string file      = Path.GetFileNameWithoutExtension(image.imageFile.FileName);
            string extension = Path.GetExtension(image.imageFile.FileName);
            string filename  = file + DateTime.Now.ToString("yymmssfff") + extension;

            using (imagesGalleryEntities db = new imagesGalleryEntities())
            {
                pictures addpicture = new pictures();
                try
                {
                    addpicture.id = (from picture in db.pictures
                                     select picture.id).Max() + 1;
                }
                catch (System.InvalidOperationException ex)
                {
                    addpicture.id = 0;
                };
                addpicture.name             = post;
                addpicture.description      = description;
                addpicture.publication_date = DateTime.Now;
                var Ouser = (user)Session["User"];
                addpicture.user_id      = Ouser.id;
                addpicture.picture_path = "/img/userspictures/" + filename;
                filename = Path.Combine(Server.MapPath("~/img/userspictures/"), filename);
                image.imageFile.SaveAs(filename);


                db.pictures.Add(addpicture);
                db.SaveChanges();
            }
            ModelState.Clear();

            return(View());
        }
        public async Task <IActionResult> Create([Bind("PicID,StoragePath")] pictures pictures)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pictures);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pictures));
        }
Esempio n. 4
0
        public static void Initialize(HieromemicsContext context)
        {
            context.Database.EnsureCreated();

            if (context.users.Any())
            {
                return;
            }

            var usrs = new users[]
            {
                new users
                {
                    userName = "******"
                },
                new users
                {
                    userName = "******"
                },
                new users
                {
                    userName = "******"
                },
                new users
                {
                    userName = "******"
                }
            };

            foreach (users u in usrs)
            {
                context.users.Add(u);
            }
            context.SaveChanges();

            var pics = new pictures[]
            {
                new pictures
                {
                    StoragePath = "https://www.ancient-origins.net/sites/default/files/field/image/Ancient-Egyptian-Hieroglyphs.jpg"
                },
                new pictures
                {
                    StoragePath = "https://askleo.askleomedia.com/wp-content/uploads/2015/07/2149-600x315.jpg"
                }
            };

            foreach (pictures p in pics)
            {
                context.pictures.Add(p);
            }
            context.SaveChanges();
        }