예제 #1
0
        public ActionResult <Pas> Put(string ime, [FromBody] ZadatakDTO model)
        {
            var data = _service.GetAll().FirstOrDefault(d => d.NazivZadatka.Equals(ime));

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

            data.NazivZadatka = model.NazivZadatka;
            data.Teren        = model.Teren;
            data.Datum        = model.Datum;


            _service.Update(data);
            return(NoContent());
        }
        public IActionResult Index(string message)
        {
            try
            {
                if (message == null)
                {
                    message = string.Empty;
                }

                List <Zadatak> zadaci = service.GetAll().ToList();

                foreach (Zadatak z in zadaci)
                {
                    if (z.Datum <= DateTime.Now && z.Status == "Kreiran")
                    {
                        Zadatak zadatakIzBaze = service.FindById(z.Id);
                        if (zadatakIzBaze == null)
                        {
                            return(RedirectToAction("PageNotFound", "Home", new { message = "Zadatak čije podatke zahtevate ne postoji!" }));
                        }
                        zadatakIzBaze.Angazovanja  = z.Angazovanja;
                        zadatakIzBaze.Datum        = z.Datum;
                        zadatakIzBaze.NazivZadatka = z.NazivZadatka;
                        zadatakIzBaze.Teren        = z.Teren;
                        zadatakIzBaze.Status       = Enumerations.Status.Završen.ToString();
                        service.Update(zadatakIzBaze);
                    }
                    int i = 0;
                    foreach (Angazovanje a in z.Angazovanja)
                    {
                        if (a.Ocena != null)
                        {
                            i++;
                        }
                    }
                    if (i == z.Angazovanja.Count() && z.Status != "Ocenjen")
                    {
                        Zadatak zadatakIzBaze = service.FindById(z.Id);
                        if (zadatakIzBaze == null)
                        {
                            return(RedirectToAction("PageNotFound", "Home", new { message = "Zadatak čije podatke zahtevate ne postoji!" }));
                        }
                        zadatakIzBaze.Angazovanja  = z.Angazovanja;
                        zadatakIzBaze.Datum        = z.Datum;
                        zadatakIzBaze.NazivZadatka = z.NazivZadatka;
                        zadatakIzBaze.Teren        = z.Teren;
                        zadatakIzBaze.Status       = Enumerations.Status.Ocenjen.ToString();
                        service.Update(zadatakIzBaze);
                    }
                }

                ViewBag.ListaZadataka = service.GetAll().ToList();
                List <string> naziviZadataka = service.VratiListuNazivaZadataka();
                List <int>    ang            = service.VratiBrojAngazovanjaPoZadatku();
                List <int>    poz            = service.VratiBrojPozitivihOcenaPoZadatku();

                ViewBag.Message = message;

                List <DataPoint> dataPoints1 = new List <DataPoint>();
                List <DataPoint> dataPoints2 = new List <DataPoint>();
                for (int i = 0; i < naziviZadataka.Count(); i++)
                {
                    if (zadaci.ElementAt(i).Status == "Ocenjen")
                    {
                        dataPoints1.Add(new DataPoint(zadaci.ElementAt(i).NazivZadatka, poz.ElementAt(i)));
                    }
                }
                for (int i = 0; i < naziviZadataka.Count(); i++)
                {
                    if (zadaci.ElementAt(i).Status == "Ocenjen")
                    {
                        dataPoints2.Add(new DataPoint(zadaci.ElementAt(i).NazivZadatka, ang.ElementAt(i)));
                    }
                }


                ViewBag.DataPoints1 = JsonConvert.SerializeObject(dataPoints1);
                ViewBag.DataPoints2 = JsonConvert.SerializeObject(dataPoints2);

                return(View());
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Error", "Home", new { message = ex.Message }));
            }
        }