예제 #1
0
 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));
     }
 }
예제 #2
0
        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();
            }
        }
예제 #3
0
 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;
            }
        }