Exemplo n.º 1
0
        public IActionResult Obrisi(int id)
        {
            Korisnik k = HttpContext.GetLogiraniKorisnik();
            int      trenerId = 0;
            string   obrisan = null, greska = null;

            if (k.Trener != null)
            {
                trenerId = k.Trener.TrenerId;
            }

            LicniClanovi lc = _ctx.LicniClanovi.FirstOrDefault(x => x.ClanId == id && x.TrenerId == trenerId);

            if (lc != null)
            {
                _ctx.LicniClanovi.Remove(lc);
                _ctx.SaveChanges();

                Clan clan = _ctx.Clanovi.Find(id);

                obrisan = "Uspješno ste obrisali člana " + clan.Ime.ToString() + " " + clan.Prezime.ToString() + ".";
            }
            else
            {
                greska = "Došlo je do greške. Pokušajte ponovo.";
            }

            return(RedirectToAction("Index", new { _obrisan = obrisan, _greska = greska }));
        }
Exemplo n.º 2
0
        public IActionResult Snimi(int id)
        {
            Korisnik korisnik = HttpContext.GetLogiraniKorisnik();
            var      trenerId = korisnik.Trener.TrenerId;

            LicniClanovi lc = _ctx.LicniClanovi.FirstOrDefault(x => x.ClanId == id && x.TrenerId == trenerId);

            Clan clan = _ctx.Clanovi.Find(id);

            if (lc != null)
            {
                string greska = "Nije moguće dodati člana " + clan.Ime + " " + clan.Prezime;
                return(RedirectToAction("Index", new { _greska = greska }));
            }


            LicniClanovi c = new LicniClanovi();

            _ctx.LicniClanovi.Add(c);

            c.Clan     = _ctx.Clanovi.Find(id);
            c.ClanId   = id;
            c.TrenerId = trenerId;

            _ctx.SaveChanges();

            string dodan = "Uspješno ste dodali člana " + clan.Ime + " " + clan.Prezime;

            return(RedirectToAction("Index", new { _dodan = dodan }));
        }
Exemplo n.º 3
0
        public IActionResult Index(string _obrisan, string _dodan, string _greska)
        {
            List <SviClanoviVM> model      = new List <SviClanoviVM>();
            List <Clan>         sviClanovi = _ctx.Clanovi
                                             .Include(x => x.VrstaClanarine)
                                             .Include(x => x.Grad)
                                             .ToList();
            List <LicniClanovi> licniClanovi = _ctx.LicniClanovi
                                               .Include(x => x.Clan)
                                               .Include(x => x.Trener)
                                               .ToList();

            Korisnik k = HttpContext.GetLogiraniKorisnik();

            foreach (Clan x in sviClanovi)
            {
                LicniClanovi temp = new LicniClanovi();
                if (licniClanovi.Count != 0)
                {
                    temp = licniClanovi.Where(y => y.ClanId == x.ClanId && y.TrenerId == k.Trener.TrenerId).FirstOrDefault();
                }

                SviClanoviVM m = new SviClanoviVM();

                m.Clan   = x;
                m.ClanId = x.ClanId;

                if (temp != null && x.ClanId == temp.ClanId)
                {
                    m.LicniClan = "Da";
                }
                else
                {
                    m.LicniClan = "Ne";
                }

                model.Add(m);
            }

            if (_obrisan != null)
            {
                ViewData["brisanje"] = _obrisan;
            }
            if (_dodan != null)
            {
                ViewData["dodavanje"] = _dodan;
            }
            if (_greska != null)
            {
                ViewData["greska"] = _greska;
            }
            _obrisan = _dodan = _greska = null;
            return(View(model));
        }
Exemplo n.º 4
0
        public IActionResult Obrisi(int id)
        {
            Clan clan = _ctx.Clanovi.Find(id);

            LicniClanovi                  lc = _ctx.LicniClanovi.FirstOrDefault(x => x.ClanId == id);
            List <Lajkovi>                l  = _ctx.Lajkovi.Where(x => x.ClanId == id).ToList();
            List <ObjaveClanova>          o  = _ctx.ObjaveClanova.Where(x => x.ClanId == id).ToList();
            List <KomentariObjavaClanova> k  = _ctx.KomentariObjavaClanova.Where(x => x.ClanId == id).ToList();
            List <Followers>              f  = _ctx.Followeri.Where(x => x.PratiteljClanId == id || x.ZapraceniClanId == id).ToList();

            if (f.Count != 0)
            {
                foreach (var nn in f)
                {
                    _ctx.Followeri.Remove(nn);
                }
            }
            if (l != null)
            {
                foreach (var nn in l)
                {
                    _ctx.Lajkovi.Remove(nn);
                }
            }
            if (o != null)
            {
                foreach (var nn in o)
                {
                    _ctx.ObjaveClanova.Remove(nn);
                }
            }
            if (k != null)
            {
                foreach (var nn in k)
                {
                    _ctx.KomentariObjavaClanova.Remove(nn);
                }
            }
            if (lc != null)
            {
                _ctx.LicniClanovi.Remove(lc);
            }
            _ctx.Clanovi.Remove(clan);
            _ctx.SaveChanges();

            ViewData["porukaUspjesnoBrisanje"] = "Uspješno ste obrisali člana " + clan.Ime + " " + clan.Prezime;

            return(RedirectToAction("Index"));
        }