예제 #1
0
        public async Task <ActionResult <AnketaEntity> > PostAnketaEntity(AnketaDTO anketaDTO)
        {
            AnketaEntity anketa = new AnketaEntity();

            anketa.status           = true;
            anketa.Naziv            = anketaDTO.Naziv;
            anketa.VrijemeKreiranja = anketaDTO.VrijemeKreiranja;
            anketa.Opis             = anketaDTO.Opis;
            List <PitanjeEntity> listaPitanja = new List <PitanjeEntity>();

            foreach (var pitanje in anketaDTO.PitanjeDTO)
            {
                var p = new PitanjeEntity();
                p.TekstPitanja = pitanje.TekstPitanja;
                p.TipPitanja   = new TipPitanjaEntity();
                var query = _context.TipoviPitanja.SingleOrDefault(tip => tip.VrstaPitanja == pitanje.VrstaPitanja);
                if (query == null)
                {
                    p.TipPitanja.VrstaPitanja = pitanje.VrstaPitanja;
                }
                else
                {
                    p.TipPitanja.VrstaPitanja = query.VrstaPitanja;
                    p.TipPitanja.Id           = query.Id;
                }
                //p.TipPitanja.VrstaPitanja = pitanje.VrstaPitanja;
                p.PonudeniOdgovori = new List <PonudeniOdgovorEntity>();
                foreach (var odgovor in pitanje.ponudeniOdgovori)
                {
                    var ponudeniOdgovor = new PonudeniOdgovorEntity();
                    ponudeniOdgovor.DefiniraniOdgovor = odgovor;
                    p.PonudeniOdgovori.Add(ponudeniOdgovor);
                }
                listaPitanja.Add(p);
                anketa.Pitanja = listaPitanja;
                //await _context.Pitanja.AddAsync(p);
                //_context.SaveChanges();
            }
            await _context.Ankete.AddAsync(anketa);

            _context.SaveChanges();
            return(Ok("Kreirana je nova anketa! "));
        }
예제 #2
0
        public ResultDTO EditUser([FromRoute] string id, [FromBody] AnketaDTO model)
        {
            var anketas = _context.anketa.FirstOrDefault(t => t.AnketaId == id);

            anketas.FullName = model.FullName;
            anketas.Title    = model.Title;
            anketas.Text     = model.Text;
            anketas.Phone    = model.Phone;
            anketas.Servant  = model.Servant;
            anketas.isClose  = model.isClose;
            anketas.id       = model.id;



            _context.SaveChanges();

            return(new ResultDTO
            {
                Status = 200,
                Message = "OK"
            });
        }
예제 #3
0
        public IEnumerable <AnketaDTO> getAnketa()
        {
            List <AnketaDTO> data = new List <AnketaDTO>();

            var dataFromDB = _context.anketa.Where(t => t.isClose == false).ToList();

            foreach (var item in dataFromDB)
            {
                AnketaDTO temp = new AnketaDTO();

                temp.FullName = item.FullName;
                temp.Title    = item.Title;
                temp.Text     = item.Text;
                temp.Phone    = item.Phone;
                temp.Servant  = item.Servant;
                temp.isClose  = item.isClose;
                temp.id       = item.id;


                data.Add(temp);
            }
            return(data);
        }
예제 #4
0
        public IEnumerable <AnketaDTO> GetAnketaDTOs([FromRoute] string id)
        {
            List <AnketaDTO> data = new List <AnketaDTO>();
            AnketaDTO        temp = new AnketaDTO();

            var dataFromDB = _context.anketa.ToList();

            foreach (var item in dataFromDB)
            {
                if (item.AnketaId == id)
                {
                    temp.FullName = item.FullName;
                    temp.Title    = item.Title;
                    temp.Text     = item.Text;
                    temp.Phone    = item.Phone;
                    temp.Servant  = item.Servant;
                    temp.isClose  = item.isClose;
                    temp.id       = item.id;
                }

                data.Add(temp);
            }
            return(data);
        }
예제 #5
0
        public ResultDTO AddAnketas([FromBody] AnketaDTO model)
        {
            Anketa anketas = new Anketa();

            anketas.AnketaId = Guid.NewGuid().ToString();
            anketas.FullName = model.FullName;
            anketas.Title    = model.Title;
            anketas.Text     = model.Text;
            anketas.Phone    = model.Phone;
            anketas.Servant  = model.Servant;
            anketas.isClose  = false;
            anketas.id       = model.id;
            anketas.Time     = DateTime.Now + "";

            _context.anketa.Add(anketas);

            _context.SaveChanges();

            return(new ResultDTO
            {
                Status = 200,
                Message = "OK"
            });
        }