Exemplo n.º 1
0
        public async Task <HttpResponseMessage> GetAllNamesAsync()
        {
            //Get all ppl from base
            people = await peopleService.GetAllPeopleAsync();

            if (people != null)
            {
                //initialize Mapper
                var     confgi = new MapperConfiguration(cfg => { cfg.CreateMap <Praksa.Model.Person, NamesRest>(); });
                IMapper mapper = confgi.CreateMapper();
                foreach (var person in people)
                {
                    NamesRest namesRest = mapper.Map <Praksa.Model.Person, NamesRest>(person);
                    names.Add(namesRest);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, names));

                //Show client only names and surnames
                //foreach (var person in people)
                //{
                //    names.Add(new NamesRest { FirstName = person.FirstName, LastName = person.LastName });
                //}
                //return Request.CreateResponse(HttpStatusCode.OK, names);
            }
            return(Request.CreateResponse(HttpStatusCode.NotFound, "Not found"));
        }
Exemplo n.º 2
0
        public async Task <HttpResponseMessage> GetAllNamesAsync()
        {
            var allPeople = await Service.GetAllPeopleAsync();

            List <NamesRest> names = new List <NamesRest>();

            if (allPeople != null)
            {
                foreach (var person in allPeople)
                {
                    NamesRest namesRest = Mapper.Map <Praksa.Model.Person, NamesRest>(person);
                    names.Add(namesRest);
                }
                return(Request.CreateResponse(HttpStatusCode.OK, names));
            }
            return(Request.CreateResponse(HttpStatusCode.NotFound, "Not found"));
        }
Exemplo n.º 3
0
        public async Task <HttpResponseMessage> GetAllNamesAsync()
        {
            var allPeople = await Service.GetAllPeopleAsync();

            if (allPeople != null)
            {
                //initialize Mapper
                var     config = new MapperConfiguration(cfg => { cfg.CreateMap <Praksa.Model.Person, NamesRest>(); });
                IMapper mapper = config.CreateMapper();
                foreach (var person in allPeople)
                {
                    NamesRest namesRest = mapper.Map <Praksa.Model.Person, NamesRest>(person);
                    names.Add(namesRest);
                }
                return(Request.CreateResponse(HttpStatusCode.OK, names));
            }
            return(Request.CreateResponse(HttpStatusCode.NotFound, "Not found"));
        }