示例#1
0
        public async Task <IHttpActionResult> PutGame(int id, VideoGame game)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != game.p_GameId)
            {
                return(BadRequest());
            }

            db.Entry(game).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GameExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IActionResult> PutVideo(Guid id, Video video)
        {
            if (id != video.uuid)
            {
                return(BadRequest());
            }

            _context.Entry(video).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VideoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
 public ActionResult Edit(Video editVideo)
 {
     editVideo.Date            = DateTime.Now;
     db.Entry(editVideo).State = EntityState.Modified;  //UPDATE DATABASE
     db.SaveChanges();
     return(RedirectToAction("Index"));
 }
        public async Task <IActionResult> PutVideo([FromRoute] int id, [FromBody] Video video)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != video.ID)
            {
                return(BadRequest());
            }

            _context.Entry(video).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!VideoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
示例#5
0
        //Metoda koja nam pomoze da izmenimo film, koju prosledjujemo ActionResult-u

        public ActionResult IzmeniFilm(FilmViewModel film, long?id, HttpPostedFileBase videofile)
        {
            var validImageTypes = new string[]
            {
                "image/gif",
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };

            if (film.ImageUpload == null || film.ImageUpload.ContentLength == 0)
            {
                ModelState.AddModelError("ImageUpload", "Polje je obavezno");
            }
            else if (!validImageTypes.Contains(film.ImageUpload.ContentType))
            {
                ModelState.AddModelError("ImageUpload", "Molimo odaberite podatak sa ovim ekstenzijama: GIF, JPG ili PNG.");
            }


            var filmovi = _context.Film.Find(id);

            if (filmovi == null)
            {
                return(new HttpNotFoundResult());
            }

            filmovi.Naziv    = film.Naziv;
            filmovi.Zanr     = film.Zanr.ToString();
            filmovi.Ocena    = film.Ocena;
            filmovi.Godina   = film.Godina;
            filmovi.Trajanje = film.Trajanje;


            if (film.ImageUpload != null && film.ImageUpload.ContentLength > 0)
            {
                var uploadDir = "~/Slike";
                var imagePath = Path.Combine(Server.MapPath(uploadDir), film.ImageUpload.FileName);
                var imageUrl  = Path.Combine(uploadDir, film.ImageUpload.FileName);
                film.ImageUpload.SaveAs(imagePath);
                filmovi.Slika = imageUrl;
            }
            if (videofile != null)
            {
                string filename = Path.GetFileName(videofile.FileName);
                if (videofile.ContentLength < 2147483647)
                {
                    videofile.SaveAs(Server.MapPath("/Videofiles/" + videofile.FileName));
                }

                filmovi.Video = "/Videofiles/" + videofile.FileName;
            }
            _context.Entry(filmovi).State = EntityState.Modified;
            _context.SaveChanges();
            return(View(film));
        }
示例#6
0
 public ActionResult Edit([Bind(Include = "Id,Profileid,Videotitle,Vlink,Shared,Datein,Like,Dislike,Views,Info")] Video video)
 {
     if (ModelState.IsValid)
     {
         db.Entry(video).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(video));
 }
示例#7
0
 public ActionResult Edit([Bind(Include = "ID,TagName")] Tag tag)
 {
     if (ModelState.IsValid)
     {
         db.Entry(tag).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(tag));
 }
示例#8
0
 public ActionResult Edit([Bind(Include = "ID,Title,MyDescription,FrameRate,EncodingID")] Video video)
 {
     if (ModelState.IsValid)
     {
         db.Entry(video).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.EncodingID = new SelectList(db.Encodings, "ID", "Codec", video.EncodingID);
     return(View(video));
 }
示例#9
0
 public ActionResult Edit([Bind(Include = "ID,VideoID,TagID")] VideoTag videoTag)
 {
     if (ModelState.IsValid)
     {
         db.Entry(videoTag).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.TagID   = new SelectList(db.Tags, "ID", "TagName", videoTag.TagID);
     ViewBag.VideoID = new SelectList(db.Videos, "ID", "Title", videoTag.VideoID);
     return(View(videoTag));
 }
示例#10
0
        public ActionResult Edit([Bind(Include = "Id,Name,UserId,Picture")] Profile profile, HttpPostedFileBase upload)
        {
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    using (var reader = new System.IO.BinaryReader(upload.InputStream))
                    {
                        profile.Picture = reader.ReadBytes(upload.ContentLength);
                    }
                }
                db.Entry(profile).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(profile));
        }
        //Metoda koja nam pomoze da izmenimo korisnika, koju prosledjujemo ActionResult-u
        public ActionResult IzmeniKorisnika(KorisnikViewModel korisnik, long?id)
        {
            var k = _context.Korisnik.Find(id);

            if (k == null)
            {
                return(new HttpNotFoundResult());
            }

            k.Ime           = korisnik.Ime;
            k.Prezime       = korisnik.Prezime;
            k.KorisnickoIme = korisnik.KorisnickoIme;
            k.Lozinka       = korisnik.Lozinka;
            k.PravoPristupa = korisnik.PravoPristupa;

            _context.Entry(k).State = EntityState.Modified;
            _context.SaveChanges();
            return(View(korisnik));
        }
示例#12
0
        public async Task <IActionResult> Edit(Video video, List <int> Tags)
        {
            if (ModelState.IsValid)
            {
                using (var transaction = await _context.Database.BeginTransactionAsync())
                {
                    try
                    {
                        _context.Entry(video).State = EntityState.Modified;
                        await _context.SaveChangesAsync();

                        _context.VideoTag.RemoveRange(_context.VideoTag.Where(v => v.VideoId == video.Id));
                        await _context.SaveChangesAsync();

                        foreach (var tag in Tags)
                        {
                            await _context.VideoTag.AddAsync(new VideoTag {
                                VideoId = video.Id,
                                TagId   = tag
                            });

                            await _context.SaveChangesAsync();
                        }

                        transaction.Commit();
                    } catch (Exception ex)
                    {
                        throw ex;
                    }
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.Tags = await _context.Tags.Where(t => t.EsVisible).ToListAsync();

            return(View(video));
        }