Example #1
0
        public async Task <IActionResult> UpdateIzabran(Izabran model)
        {
            _context.Entry(model.nagrada).State   = EntityState.Unchanged;
            _context.Entry(model.OrgOdb).State    = EntityState.Unchanged;
            _context.Entry(model.Pozoriste).State = EntityState.Unchanged;
            _context.Entry(model.ugovor).State    = EntityState.Unchanged;

            model.datumSklapanja        = DateTime.Now;
            _context.Entry(model).State = EntityState.Modified;

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

            return(Ok());
        }
Example #2
0
        public async Task <ActionResult <Izabran> > GetIzabran(int id)
        {
            Izabran model = await _context.Izabrani
                            .Include(x => x.OrgOdb)
                            .Include(x => x.Pozoriste)
                            .ThenInclude(x => x.sale)
                            .Include(x => x.ugovor)
                            .Include(x => x.nagrada)
                            .FirstOrDefaultAsync(i => i.id == id);

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

            return(model);
        }
Example #3
0
        public async Task <ActionResult <Izabran> > DeletIzabran(int id)
        {
            Izabran model = await _context.Izabrani
                            .Include(x => x.OrgOdb)
                            .Include(x => x.Pozoriste)
                            .FirstOrDefaultAsync(i => i.id == id);

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

            _context.Entry(model.nagrada).State   = EntityState.Modified;
            _context.Entry(model.ugovor).State    = EntityState.Modified;
            _context.Entry(model.OrgOdb).State    = EntityState.Modified;
            _context.Entry(model.Pozoriste).State = EntityState.Modified;

            _context.Entry(model).State = EntityState.Deleted;
            await _context.SaveChangesAsync();

            return(Ok());
        }
Example #4
0
        public async Task <ActionResult <Izabran> > AddIzabran(Izabran model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (ValidateModel(model, true))
            {
                _context.Entry(model.nagrada).State   = EntityState.Unchanged;
                _context.Entry(model.ugovor).State    = EntityState.Unchanged;
                _context.Entry(model.OrgOdb).State    = EntityState.Unchanged;
                _context.Entry(model.Pozoriste).State = EntityState.Unchanged;
                _context.Izabrani.Add(model);
                await _context.SaveChangesAsync();

                return(CreatedAtAction("GetIzabran", new { id = model.id }, model));
            }
            else
            {
                return(BadRequest());
            }
        }
Example #5
0
 private bool ValidateModel(Izabran model, bool isPost)
 {
     return(true);
 }