示例#1
0
        public async Task <HttpResponseMessage> UpdatePredmetAsync(PredmetViewModel updateP)
        {
            try
            {
                if (updateP != null)
                {
                    PredmetViewModel toBeUpdated = Mapper.Map <PredmetViewModel>(await predmetiService.GetAsync(updateP.Id));

                    if (toBeUpdated == null)
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Nije pronađen traženi predmet."));
                    }
                    else
                    {
                        toBeUpdated.Ime_predmeta = updateP.Ime_predmeta;
                    }

                    var response = await predmetiService.UpdateAsync(Mapper.Map <IPredmetDomainModel>(toBeUpdated));

                    return(Request.CreateResponse(HttpStatusCode.OK, response));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Predmet nije pronađen"));
                }
            }catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Greska prilikom promjene"));
            }
        }
        public ActionResult SacuvajPredmet(PredmetViewModel predmetViewModel)
        {
            //proverava se da li predmet vec postoji u bazi
            if (_context.Predmeti.Where(p => p.NazivPredmeta == predmetViewModel.Predmet.NazivPredmeta).Any())
            {
                ModelState.AddModelError("Predmet.NazivPredmeta", "Predmet već postoji!");
            }

            if (ModelState.IsValid)
            {
                try
                {
                    Predmet predmet = new Predmet();
                    predmet.NazivPredmeta      = predmetViewModel.Predmet.NazivPredmeta;
                    predmet.TipOcenePredmetaId = predmetViewModel.Predmet.TipOcenePredmetaId;

                    _context.Predmeti.Add(predmet);
                    _context.SaveChanges();
                    return(RedirectToAction("Index", "Predmeti", new { dodatPredmet = true }));
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }
                return(View("Dodaj", new PredmetViewModel {
                    Predmet = predmetViewModel.Predmet, Greska = true
                }));
            }
            else
            {
                return(View("Dodaj", new PredmetViewModel {
                    Predmet = predmetViewModel.Predmet, Greska = true
                }));
            }
        }
示例#3
0
        public ActionResult Details(int id)
        {
            var student  = DataProvider.GetStudent(id);
            var predmeti = DataProvider.GetPredmeti(id);

            var predmetViewModel = new PredmetViewModel()
            {
                Student = student, Predmeti = predmeti
            };

            return(View(predmetViewModel));
        }
示例#4
0
        public ActionResult Details(int id)
        {
            List <Predmet> predmeti = DataProvider.GetPredmetiById(id);

            var predmetViewModel = new PredmetViewModel()
            {
                Predmeti = predmeti
            };


            return(View(predmetViewModel));
        }
示例#5
0
        public async Task <HttpResponseMessage> AddPredmetAsync(PredmetViewModel addObj)
        {
            try
            {
                var response = await predmetiService.AddAsync(Mapper.Map <IPredmetDomainModel>(addObj));

                return(Request.CreateResponse(HttpStatusCode.OK, response));
            } catch (Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, e));
            }
        }