public static async Task <HttpResponseMessage> Run(HttpRequestMessage req) { if (req.Method == HttpMethod.Get) { string id = req.GetQueryNameValuePairs() .FirstOrDefault(q => q.Key == "id") .Value; if (!string.IsNullOrEmpty(id)) { MongoConfig.RegisterMappings(); var mongoClient = new MongoClient(ConfigurationManager.AppSettings["MongoDbConnectionString"]); var customersCollection = mongoClient.GetDatabase(ConfigurationManager.AppSettings["MongoDbDatabase"]) .GetCollection <RoboBank.Customer.Domain.Customer>("customers"); var customerApplicationService = new CustomerApplicationService(new MongoCustomerRepository(customersCollection), new Application.Adapters.Mapper()); var customerInfo = await customerApplicationService.GetByIdAsync(id); if (customerInfo != null) { return(req.CreateResponse(HttpStatusCode.OK, AutoMapper.Mapper.Map <CustomerInfo, CustomerModel>(customerInfo))); } } return(req.CreateResponse(HttpStatusCode.NotFound)); } return(req.CreateErrorResponse(HttpStatusCode.BadRequest, "Method not supported")); }
public void Setup() { var unityContainer = UnityConfig.GetConfiguredContainer(); _objectContainer.RegisterInstanceAs(unityContainer.Resolve <IMongoCollection <Domain.Customer> >()); _objectContainer.RegisterTypeAs <RoboRestClient, IRestClient>(); MongoConfig.RegisterMappings(); }
public static async Task <HttpResponseMessage> Run(HttpRequestMessage req) { if (req.Method == HttpMethod.Get) { MongoConfig.RegisterMappings(); var mongoClient = new MongoClient(ConfigurationManager.AppSettings["MongoDbConnectionString"]); var customersCollection = mongoClient.GetDatabase(ConfigurationManager.AppSettings["MongoDbDatabase"]) .GetCollection <RoboBank.Customer.Domain.Customer>("customers"); var customerApplicationService = new CustomerApplicationService(new MongoCustomerRepository(customersCollection), new Application.Adapters.Mapper()); var customerInfos = await customerApplicationService.SearchAsync(req.GetQueryNameValuePairs()); return(req.CreateResponse(HttpStatusCode.OK, AutoMapper.Mapper.Map <List <CustomerInfo>, List <CustomerModel> >(customerInfos.ToList()))); } return(req.CreateErrorResponse(HttpStatusCode.BadRequest, "Method not supported")); }