public IHttpActionResult GetThirdPartyApp(string appId) { try { using (MususAppEntities entity = new MususAppEntities()) { var appMaster = entity.ThirdParties.FirstOrDefault(x => x.Id.ToString() == appId); ThirdPartyDto app = new ThirdPartyDto(); var rating = entity.Ratings.Where(x => x.AppId == appMaster.Id); if (rating != null && rating.Count() > 0) { app.Rating = rating.Average(x => x.Point); } else { app.Rating = 0; } MapThirdPartyApp(appMaster, app); return(Ok(app)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private void MapThirdPartyApp(ThirdParty master, ThirdPartyDto dto) { dto.CategoryId = master.CategoryId; dto.CreatedTime = master.CreatedTime; dto.DeletedTime = master.DeletedTime; dto.Description = master.Description; dto.Id = master.Id; dto.IsDeleted = master.IsDeleted; dto.ThirdPartyAppUrl = master.ThirdPartyAppUrl; dto.Title = master.Title; dto.Version = master.Version; dto.Download = master.Download ?? 0; if (master.Documents != null) { var documents = master.Documents.Split(new char[] { ';' }); dto.Documents = documents.ToList(); } }
public IHttpActionResult GetThirdPartyApps(int page = 1, int size = 10) { try { using (MususAppEntities entity = new MususAppEntities()) { List <ThirdParty> appmasters = entity.ThirdParties.OrderBy(x => x.Documents).Skip(page - 1).Take(10).ToList(); List <ThirdPartyDto> apps = new List <ThirdPartyDto>(); foreach (var app in appmasters) { ThirdPartyDto dto = new ThirdPartyDto(); MapThirdPartyApp(app, dto); apps.Add(dto); } return(Ok(apps)); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public async Task <bool> PostAsyncSuccessful(Document document, string callBackUrl, ILogger log) { try { var thirdPartyDto = new ThirdPartyDto(document, callBackUrl); var jsonString = JsonConvert.SerializeObject(thirdPartyDto); var result = await _httpClient.PostAsync("request", new StringContent(jsonString)); //Check that the HttpResponseMessage returned the expected http status code (204, 200OK, etc.). //Log any non-200 status codes along with the HttpRequestMessage that was sent. //Use polly for retries //To keep things simple, just throw an exception if not success status code result.EnsureSuccessStatusCode(); //otherwise return success. return(true); } catch (Exception ex) { log.LogError(ex, UserFriendlyMessages.ThirdPartyCommunicationFailure); throw; } }