public async Task <HttpResponseMessage> PopulateDatabaseAsync(HttpRequestMessage request) { try { if (publicationAdActivityService.ContainsData()) { return(request.CreateResponse(HttpStatusCode.OK, new { Status = true })); } //Hardcoded here, however these could be passed in to provide more flexibility var startDate = new DateTime(2011, 01, 1); var endDate = new DateTime(2011, 04, 1); var rawData = await publicationService.GetPublicationAdActivitiesAsync(new DateRange(startDate, endDate)); var publicationAdActivities = rawData.Select(model => new PublicationAdActivity { AdPages = model.AdPages, BrandId = model.BrandId, BrandName = model.BrandName, EstPrintSpend = model.EstPrintSpend, Month = DateTime.Parse(model.Month), ParentCompany = model.ParentCompany, ParentCompanyId = model.ParentCompanyId, ProductCategory = model.ProductCategory, PublicationId = model.PublicationId, PublicationName = model.PublicationName }); unitOfWork.Publications.AddRange(publicationAdActivities); await unitOfWork.SaveChangesAsync(); return(request.CreateResponse(HttpStatusCode.OK, new { Status = publicationAdActivities.Count() > 0 })); } catch (Exception) { //TODO: Add error logging return(request.CreateErrorResponse(HttpStatusCode.InternalServerError, new Exception("An internal Server error occurred, Please rest assured we have informed someone of this issue."))); } }