//[RequiredArgument] //[Input("IdToAdd")] //public InArgument<string> IdParam { get; set; } //[RequiredArgument] //[Input("IntToAdd")] //public InArgument<int> IntParam { get; set; } #endregion protected override void Execute(CodeActivityContext executionContext) { IWorkflowContext context = executionContext.GetExtension <IWorkflowContext>(); IOrganizationServiceFactory serviceFactory = executionContext.GetExtension <IOrganizationServiceFactory>(); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); if (IdParam.Get <EntityReference>(executionContext) != null) { EntityReference refAcc = IdParam.Get <EntityReference>(executionContext); string[] srt = { "emailaddress1" }; Entity email = service.Retrieve(refAcc.LogicalName, refAcc.Id, new ColumnSet(srt)); if (email.GetAttributeValue <string>("emailaddress1") != null) { string name = email.GetAttributeValue <string>("emailaddress1"); OutParam.Set(executionContext, name); } else { OutParam.Set(executionContext, "Account ->(" + refAcc.Name + ")<- email is missing"); } } else { OutParam.Set(executionContext, "There is no account in this entity"); } }
public async Task <TData <string> > SaveViewTimes([FromBody] IdParam param) { TData <string> obj = null; TData <NewsEntity> objNews = await newsBLL.GetEntity(param.Id.Value); NewsEntity newsEntity = new NewsEntity(); if (objNews.Result != null) { newsEntity.Id = param.Id.Value; newsEntity.ViewTimes = objNews.Result.ViewTimes; newsEntity.ViewTimes++; obj = await newsBLL.SaveForm(newsEntity); } else { obj = new TData <string>(); obj.Message = "文章不存在"; } return(obj); }
public void TestDeleteAssociatedOccurrencePositive() { var param = new IdParam { Id = 20 }; var associated1 = new AssociatedOccurrences { ApplicationUser = _testUser, Id = 20, ApplicationUserId = _testUser.Id, Type = "like", OccurrenceId = 1 }; _occurrencesList.Add(associated1); var response = _controller.DeleteAssociatedOccurrence(param).Result; var okResult = response.Should().BeOfType <NoContentResult>().Subject; }
public async Task <IActionResult> DeleteAssociatedOccurrence([FromBody] IdParam param) { ApplicationUser user = await _userManager.GetUserAsync(User); if (user == null) { return(Unauthorized()); } var query = _repo.GetAll(); var toDelete = query.SingleOrDefault(x => x.Id == param.Id); if (toDelete != null) { _repo.Delete(toDelete); return(NoContent()); } else { return(NotFound(string.Format($"No occurrence with id: {0} exists", param.Id))); } }
public void TestDeleteAssociatedOccurrenceNegative() { var param = new IdParam { Id = 21 }; var associated1 = new AssociatedOccurrences { ApplicationUser = _testUser, Id = 20, ApplicationUserId = _testUser.Id, Type = "like", OccurrenceId = 1 }; _occurrencesList.Add(associated1); var response = _controller.DeleteAssociatedOccurrence(param).Result; var okResult = response.Should().BeOfType <NotFoundObjectResult>().Subject; var returnString = okResult.Value.Should().BeAssignableTo <string>().Subject; }
public async Task<IHttpActionResult> GetCar(IdParam id) { var car = db.Cars.Find(id.id); if (car == null) { return await Task.FromResult(NotFound()); } HttpResponseMessage response; var client = new BingSearchContainer( new Uri("https://api.datamarket.azure.com/Bing/search/") ); client.Credentials = new NetworkCredential("accountKey", "baDOTqrNCHJ38GxTzgc8o7rpbstAS9VG5gYE8kfkHro"); var marketData = client.Composite( "image", car.model_year + " " + car.make + " " + car.model_name + " " + car.model_trim, null, null, null, null, null, null, null, null, null, null, null, null, null ).Execute(); var result = marketData.FirstOrDefault(); var image = result != null ? result.Image : null; var firstImage = image != null ? image.FirstOrDefault() : null; var mediaUrl = firstImage != null ? firstImage.MediaUrl : null; dynamic recalls; var temp = car.model_name; if(temp.Contains('&')) { var buildit = temp.Split('&'); var count = buildit.Count(); temp = ""; foreach(var item in buildit) { if(count > 1) { temp += item + "And"; } else { temp += item; } count--; } } using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("http://www.nhtsa.gov/"); try { response = await httpClient.GetAsync("webapi/api/Recalls/vehicle/modelyear/"+car.model_year+"/make/"+car.make+"/model/"+temp+"?format=json"); recalls = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); } catch (Exception e) { return InternalServerError(e); } } return Ok(new { car, mediaUrl, recalls }); }
public async Task<IHttpActionResult> GetCar(IdParam id) { var car = db.Cars.Find(id.Id); if(car == null) { return await Task.FromResult(NotFound()); } HttpResponseMessage response; var client = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/")); client.Credentials = new NetworkCredential("accountKey", "p378hNjOm0HKvheOJd/KFybFEM8wmO0orgleQPGPz9s"); var marketData = client.Composite( "image", $"{car.model_year} {car.make} {car.model_name} {car.model_trim}", null, null, null, null, null, null, null, null, null, null, null, null, null ).Execute(); var imageUrl = marketData?.FirstOrDefault()?.Image?.FirstOrDefault()?.MediaUrl; dynamic recalls; using( var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("http://www.nhtsa.gov"); try { response = await httpClient.GetAsync($"webapi/api/Recalls/vehicle/modelyear/{car.model_year}/make/{car.make}/model/{car.model_name}?format=json"); recalls = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); } catch (Exception e) { return InternalServerError(e); } } return Ok(new { car, imageUrl, recalls }); }
public async Task <IHttpActionResult> getCar(IdParam Id) { HttpResponseMessage response; string content = ""; var Car = db.Cars.Find(Id.id); var Image = ""; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://www.nhtsa.gov/"); try { response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + Car.model_year + "/make/" + Car.make + "/model/" + Car.model_name + "?format=json"); content = await response.Content.ReadAsStringAsync(); } catch (Exception e) { return(InternalServerError(e)); } } dynamic Recalls = JsonConvert.DeserializeObject(content); var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/v1/Image")); image.Credentials = new NetworkCredential("accountKey", "qZQohZcFCgVtaM/LA7T+zQyJiQiio4LDnVrIbRl04No="); //"s8cUIpKPWJ609E7VqtBbx9HNdRp9Z2NbUne/HyPgxbQ" var marketData = image.Composite( "image", Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim + " " + " NOT EBAY ", null, null, null, null, null, null, null, null, null, null, null, null, null ).Execute(); //Image = marketData.First().Image.First().MediaUrl; if (marketData != null) { var Images = marketData.FirstOrDefault().Image; //int imgCnt = Images.Count(); foreach (var Img in Images) { if (UrlCtrl.IsUrl(Img.MediaUrl)) { Image = Img.MediaUrl; break; } else { continue; } } } if (string.IsNullOrWhiteSpace(Image)) { Image = "/assets/img/no-image-available.png"; } return(Ok(new { car = Car, recalls = Recalls, image = Image })); }
public async Task<IHttpActionResult> GetCar(IdParam id) //(Selected selected) { HttpResponseMessage response; string content = ""; var Car = db.Cars.Find(id.id); //(Selected selected) passes in model, make, dynamic Recalls = ""; var Image = ""; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://www.nhtsa.gov/"); try { response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + Car.model_year + "/make/" + Car.make + "/model/" + Car.model_name + "?format=json"); content = await response.Content.ReadAsStringAsync(); } catch (Exception e) { return InternalServerError(e); } } Recalls = JsonConvert.DeserializeObject(content); var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/Search/v1/Composite")); image.Credentials = new NetworkCredential("accountKey", "/8RvXOXJ4fcq5pAnNMdOtiueBjVHcWUUFAr8ZhHPJsI"); var marketData = image.Composite( "image", Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim + " " + "NOT ebay", null, null, null, "Moderate", null, null, null, "Size:Large+Style:Photo", null, null, null, null, null ).Execute(); var Images = marketData.FirstOrDefault()?.Image; foreach (var Img in Images) { if (UrlCtrl.IsUrl(Img.MediaUrl)) { Image = Img.MediaUrl; break; } else { continue; } } if (string.IsNullOrWhiteSpace(Image)) { Image = "../img/car404.jpg"; } return Ok(new { car = Car, recalls = Recalls, image = Image }); }
public async Task<IHttpActionResult> GetCarDetails(IdParam Id) { // ---- get Recall Information ----- HttpResponseMessage response; string content = ""; var Car = db.Cars.Find(Id.id); dynamic Recalls = ""; var Image = ""; using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://www.nhtsa.gov/"); try { response = await client.GetAsync("webapi/api/Recalls/vehicle/modelyear/" + Car.model_year + "/make/" + Car.make + "/model/" + Car.model_name + "?format=json"); content = await response.Content.ReadAsStringAsync(); } catch (Exception e) { return InternalServerError(e); } } Recalls = JsonConvert.DeserializeObject(content); // --------- Get Image -------- var image = new BingSearchContainer(new Uri("https://api.datamarket.azure.com/Bing/search/")); image.Credentials = new NetworkCredential("accountKey", "ih3uuQpD5VI9IrIcovu/1dEIjaJXkB6eFMgSg9CCxGY"); var marketData = image.Composite( "image", Car.model_year + " " + Car.make + " " + Car.model_name + " " + Car.model_trim , null, null, null, null, null, null, null, null, null, null, null, null, null ).Execute(); var Images = marketData?.FirstOrDefault()?.Image; foreach (var Img in Images) { if (UrlCtrl.IsUrl(Img.MediaUrl)) { Image = Img.MediaUrl; break; } else { continue; } } return Ok(new { car = Car, recalls = Recalls, image=Image }); }