public IActionResult Snimi(NovostiDodajVM model)
        {
            KorisnickiNalog admin = HttpContext.GetLogiraniKorisnik();


            MyContext db             = new MyContext();
            string    uniqueFileName = null;

            if (model.Photo != null)
            {
                string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);

                model.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
            }
            Novosti n = new Novosti
            {
                AdresaSlike        = uniqueFileName,
                DatumVrijemeObjave = DateTime.Now,
                Tekst         = model.Novosti.Tekst,
                Naziv         = model.Novosti.Naziv,
                AdminID       = admin.KorisnickiNalogID,
                Admin         = db.Admin.Where(x => x.KorisnickiNalogID == admin.KorisnickiNalogID).FirstOrDefault(),
                KratkiSadrzaj = model.Novosti.KratkiSadrzaj
            };

            db.Novosti.Add(n);
            db.SaveChanges();
            db.Dispose();
            return(RedirectToAction("Prikazi"));
        }
예제 #2
0
        public async Task <IActionResult> Dodaj(AdminNovostiVM model)
        {
            if (!ModelState.IsValid)
            {
                model.Title = "Dodaj";
                return(View("Views/Admin/Novosti/Dodaj.cshtml", model));
            }

            string uniqueFileName = UploadedFile(model);
            Slika  slika          = new Slika
            {
                Putanja = uniqueFileName
            };

            dbContext.Add(slika);
            await dbContext.SaveChangesAsync();

            Novosti novost = new Novosti
            {
                Naslov  = model.Naslov,
                Text    = model.Text,
                SlikaId = slika.Id,
                Datum   = DateTime.Now.ToString("dd\\/MM\\/yyyy")
            };

            dbContext.Add(novost);
            await dbContext.SaveChangesAsync();

            return(RedirectToRoute("AdminNovostiIndex"));
        }
예제 #3
0
        public IHttpActionResult PutNovosti(int id, Novosti novosti)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != novosti.NovostID)
            {
                return(BadRequest());
            }

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

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NovostiExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #4
0
        public async Task <IActionResult> Obrisi(int id)
        {
            try
            {
                Novosti novost = dbContext.Novosti.Find(id);
                dbContext.Novosti.Attach(novost);
                dbContext.Novosti.Remove(novost);

                Slika slika = new Slika()
                {
                    Id = novost.SlikaId
                };
                dbContext.Slika.Attach(slika);
                dbContext.Slika.Remove(slika);

                await dbContext.SaveChangesAsync();
            }
            catch (Exception)
            {
                if (!dbContext.Novosti.Any(i => i.Id == id))
                {
                    return(NotFound());
                }
            }
            return(RedirectToRoute("AdminNovostiIndex"));
        }
예제 #5
0
        public IActionResult Obrisi(int NovostiID)
        {
            Novosti             n     = _context.Novosti.Find(NovostiID);
            List <NovostiSlike> slike = _context.NovostiSlike.Where(x => x.NovostiID == NovostiID).ToList();

            if (n == null)
            {
                TempData["error_poruka"] = "Novost ne postoji.";
            }
            else
            {
                if (slike != null)
                {
                    foreach (NovostiSlike x in slike)
                    {
                        _context.Remove(x);
                    }
                }
                _context.Remove(n);
                try
                {
                    _context.SaveChanges();
                }
                catch
                {
                    TempData["error_poruka"] = "Nemoguće izbrisati novost. Vezana je za nešto u bazi. ";
                }
                TempData["success_poruka"] = "Uspješno ste izbrisali novost";
            }
            return(RedirectToAction("Prikazi"));
        }
        public IActionResult UrediSnimi(NovostiUrediVM model)
        {
            MyContext db      = new MyContext();
            Novosti   novosti = db.Novosti.Where(x => x.NovostiID == model.id).FirstOrDefault();

            if (model.adresaaSlike != null)
            {
                novosti.AdresaSlike = model.adresaaSlike;
            }

            string    uniqueFileName = null;
            IFormFile slika          = model.Photo;

            if (slika != null)
            {
                string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "images");

                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);

                model.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                novosti.AdresaSlike = uniqueFileName;
            }
            novosti.NovostiID          = model.id;
            novosti.DatumVrijemeObjave = model.DatumVrijemeObjave;
            novosti.Naziv         = model.Naziv;
            novosti.Tekst         = model.Tekst;
            novosti.KratkiSadrzaj = model.KratkiSadrzaj;
            db.SaveChanges();
            db.Dispose();
            return(RedirectToAction("Prikazi/" + model.id));
        }
예제 #7
0
        public async Task <IActionResult> Uredi(AdminNovostiVM model)
        {
            if (!ModelState.IsValid)
            {
                model.Title = "Dodaj";
                return(View("Views/Admin/Novosti/Uredi.cshtml", model));
            }

            Novosti novost = dbContext.Novosti.Find(model.Id);

            novost.Naslov = model.Naslov;
            novost.Text   = model.Text;

            if (model.SlikaFile != null)
            {
                string uniqueFileName = UploadedFile(model);
                Slika  slika          = new Slika
                {
                    Putanja = uniqueFileName
                };
                dbContext.Add(slika);
                await dbContext.SaveChangesAsync();

                novost.SlikaId = slika.Id;
            }

            dbContext.Update(novost);
            await dbContext.SaveChangesAsync();

            return(RedirectToRoute("AdminNovostiIndex"));
        }
예제 #8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Naslov,Tekst,Link")] Novosti novosti)
        {
            if (id != novosti.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(novosti);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NovostiExists(novosti.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(novosti));
        }
예제 #9
0
 public NovostiDetailPage(Novosti novosti)
 {
     InitializeComponent();
     BindingContext = model = new NovostiDetailViewModel()
     {
         Novosti = novosti
     };
 }
예제 #10
0
 public NovostiDetaljiPage(Novosti n)
 {
     InitializeComponent();
     BindingContext = model = new NovostiDetaljiViewModel()
     {
         Novost = n
     };
 }
        public IActionResult Obrisi(int id)
        {
            MyContext db      = new MyContext();
            Novosti   novosti = db.Novosti.Find(id);

            db.Novosti.Remove(novosti);
            db.SaveChanges();
            return(View("Prikazi"));
        }
        public IActionResult Dodaj(int NovostiID)
        {
            Novosti             n     = _context.Novosti.Find(NovostiID);
            NovostiSlikeDodajVM model = new NovostiSlikeDodajVM();

            model.NovostiID = NovostiID;
            model.Naslov    = n.Naslov;
            return(View("Dodaj", model));
        }
        public IActionResult Obrisi(int id)
        {
            MyContext db = new MyContext();
            Novosti   n  = db.Novosti.Find(id);

            db.Novosti.Remove(n);
            db.SaveChanges();
            db.Dispose();
            return(RedirectToAction("Prikazi"));
        }
예제 #14
0
        public async Task <IActionResult> Create([Bind("Id,Naslov,Tekst,Link")] Novosti novosti)
        {
            if (ModelState.IsValid)
            {
                _context.Add(novosti);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(novosti));
        }
예제 #15
0
        public IHttpActionResult GetNovosti(int id)
        {
            Novosti novosti = db.Novostis.Find(id);

            if (novosti == null)
            {
                return(NotFound());
            }

            return(Ok(novosti));
        }
예제 #16
0
        public IHttpActionResult PostNovosti(Novosti novosti)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Novostis.Add(novosti);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = novosti.NovostID }, novosti));
        }
예제 #17
0
        public IHttpActionResult DeleteNovosti(int id)
        {
            Novosti novosti = db.Novostis.Find(id);

            if (novosti == null)
            {
                return(NotFound());
            }

            db.Novostis.Remove(novosti);
            db.SaveChanges();

            return(Ok(novosti));
        }
        public IActionResult Uredi(int id)
        {
            MyContext      db    = new MyContext();
            Novosti        n     = db.Novosti.Where(x => x.NovostiID == id).FirstOrDefault();
            NovostiUrediVM model = new NovostiUrediVM()
            {
                id                 = n.NovostiID,
                KratkiSadrzaj      = n.KratkiSadrzaj,
                Tekst              = n.Tekst,
                DatumVrijemeObjave = n.DatumVrijemeObjave,
                Naziv              = n.Naziv,
                adresaaSlike       = n.AdresaSlike
            };

            db.Dispose();
            return(View(model));
        }
예제 #19
0
        public IActionResult Uredi(int NovostiID)
        {
            Novosti n = _context.Novosti.Find(NovostiID);

            if (n == null)
            {
                TempData["error_poruka"] = "Novost ne postoji. ";
            }
            NovostiUrediVM model = new NovostiUrediVM();

            model.Naslov             = n.Naslov;
            model.Text               = n.Text;
            model.DatumObjavljivanja = n.DatumObjavljivanja;
            // model.Slika = n.Slika;

            return(View("Uredi", model));
        }
예제 #20
0
        public IActionResult PrikaziNovostiCir(int NovostiID)
        {
            Novosti            o     = _context.Novosti.Where(x => x.NovostiID == NovostiID).FirstOrDefault();
            NovostiSlikeViseVM model = new NovostiSlikeViseVM();

            model.NovostiID          = NovostiID;
            model.Naslov             = _translate.ConvertLatinToCyrillic(o.Naslov);
            model.Text               = _translate.ConvertLatinToCyrillic(o.Text);
            model.SlikaThumbnail     = o.Slika;
            model.DatumObjavljivanja = o.DatumObjavljivanja;
            model.lista              = _context.NovostiSlike.Where(x => x.NovostiID == NovostiID).Select(x => new NovostiSlikeViseVM.Row()
            {
                NovostiSlikaID = x.NovostiSlikeID,
                Slika          = x.Slika
            }).ToList();

            return(View(model));
        }
예제 #21
0
        public IActionResult Snimi(NovostiUrediVM input)
        {
            Novosti n;

            if (input.NovostiID == 0)
            {
                n = new Novosti();
                _context.Add(n);
                TempData["success_poruka"] = "Uspješno ste dodali novost. ";
            }
            else
            {
                n = _context.Novosti.Find(input.NovostiID);
            }
            n.NovostiID          = input.NovostiID;
            n.Naslov             = input.Naslov;
            n.Text               = input.Text;
            n.DatumObjavljivanja = input.DatumObjavljivanja;
            if (input.UploadSlike != null)
            {
                using (var memoryStream = new MemoryStream())
                {
                    input.UploadSlike.Slika.CopyTo(memoryStream);
                    if (memoryStream.Length < 2097152)
                    {
                        n.Slika = memoryStream.ToArray();
                    }
                    else
                    {
                        ModelState.AddModelError("File", "File je prevelik.");
                    }
                }
            }
            _context.SaveChanges();
            if (input.NovostiID == 0)
            {
                TempData["success_poruka"] = "Uspješno ste dodali novost. ";
            }
            else
            {
                TempData["success_poruka"] = "Uspješno ste izmijenili podatke o novosti. ";
            }
            return(RedirectToAction("Prikazi"));
        }
예제 #22
0
        private async void GetNovost(string novostiId)
        {
            HttpResponseMessage response = novostiService.getActionResponse(novostiId);

            if (response.IsSuccessStatusCode)
            {
                novosti = response.Content.ReadAsAsync <Novosti>().Result;
                nazivNovostiTxt.Text         = novosti.Naziv;
                sadrzajNovostiTextBlock.Text = novosti.Sadrzaj;
            }
            if (novosti.Slika != null)
            {
                MemoryStream ms    = new MemoryStream(novosti.Slika);
                BitmapImage  image = new BitmapImage();

                await image.SetSourceAsync(ms.AsRandomAccessStream());

                novostImage.Source = image;
            }
            else
            {
                novostImage.Source = new BitmapImage(new Uri("ms-appx:///Assets/add-to-cart-light.png"));
            }
        }
예제 #23
0
 public UrediNovostiPage(Novosti Novosti)
 {
     InitializeComponent();
     BindingContext  = NovostiVM = new UrediNovostiVM(Novosti);
     NovostiVM.Slika = Novosti.Slika;
 }
 public UrediNovostiVM(Novosti novosti)
 {
     this.Novosti = novosti;
 }