Ejemplo n.º 1
0
        public List <User> GetUsers()
        {
            List <User> listUserModel = new List <User>();
            UserCRUD    userCrud      = new UserCRUD();

            listUserModel = userCrud.GetUsers();
            return(listUserModel);
        }
        public UserListResponse Search(long id, SearchRequest req)
        {
            UserListResponse resp = new UserListResponse();

            try
            {
                if (ValidateRequest.SearchRequest(req))
                {
                    var userCrud = new UserCRUD();
                    if (userCrud.IsUserExists(id))
                    {
                        List <string> states            = req.Filters.Where(x => x.Filters == EFilters.States).Select(x => x.Values).FirstOrDefault();
                        List <string> homeType          = req.Filters.Where(x => x.Filters == EFilters.HomeType).Select(x => x.Values).FirstOrDefault();
                        List <string> homeZipCode       = req.Filters.Where(x => x.Filters == EFilters.HomeZipCode).Select(x => x.Values).FirstOrDefault();
                        List <string> numberOfKids      = req.Filters.Where(x => x.Filters == EFilters.NumberOfKids).Select(x => x.Values).FirstOrDefault();
                        int           minAge            = req.Filters.Where(x => x.Filters == EFilters.Age).Select(x => x.MinAge).FirstOrDefault();
                        int           maxAge            = req.Filters.Where(x => x.Filters == EFilters.Age).Select(x => x.MaxAge).FirstOrDefault();
                        bool          isAgeFilterExists = req.Filters.Any(x => x.Filters == EFilters.Age);

                        var userList = userCrud.GetUsers(states, homeType, homeZipCode, numberOfKids, isAgeFilterExists, minAge, maxAge);
                        if (userList.Count > 0)
                        {
                            resp.User = userList;
                            resp.OK();
                        }
                        else
                        {
                            resp.NotFound();
                        }
                    }
                    else
                    {
                        resp.Conflict();
                    }
                }
                else
                {
                    resp.BadRequest();
                }
            }
            catch (Exception es)
            {
                string reqData = JsonConvert.SerializeObject(req);
                logger.Error(string.Format("SearchRequest, UserID={0}, Req={1}", id, reqData));
                logger.Error("SearchRequest " + es.StackTrace);
                resp.InternalServerError();
            }
            return(resp);
        }