public BannerResponse GetNextBanner(String nickname, String password) { if (String.IsNullOrEmpty(nickname)) { throw new ArgumentNullException("nickname"); } if (String.IsNullOrEmpty(password)) { throw new ArgumentNullException("password"); } var member = Member.GetMemberViaNicknamePassword(nickname, password); BannerResponse response = null; try { var banner = data.Banner.GetNextBanner(BannerType.MobileBanner, "Next2Friends Mobile"); response = new BannerResponse() { Base64BannerBinary = data.Photo.ImageToBase64String( new Bitmap(@"\\www\live" + banner.FileLocation)), BannerURL = @"http://www.next2friends.com/ad/" + banner.WebBannerID }; } catch (Exception e) { throw e; } return(response); }
public BannerResponse Execute(int id) { var bannerResponse = new BannerResponse(); try { Log.Information("Recuperando banner por Id : [{Id}]", id); var banner = Repository.SingleOrDefault(g => g.Id == id); if (banner == null) { var exception = new Exception($"banner no encontrado por id : [{id}]."); Log.Error(exception, EXCEPTION_MESSAGE_TEMPLATE, exception.Message); HandleErrors(bannerResponse, exception, 404); } else { //NOTE: Not sure if I want to do something like AutoMapper for this example. bannerResponse.Banner = banner; bannerResponse.StatusCode = 200; } } catch (Exception exception) { Log.Error(exception, "Error al obtener banner por Id: [{Id}].", id); HandleErrors(bannerResponse, exception); } return(bannerResponse); }
public BannerResponse Execute(UpdateBannerInput input) { var bannerResponse = new BannerResponse(); try { CheckInputValidity(input); Log.Information("Actualizando Banner por Id: [{Id}] con nuevo nombre: [{NewTitle}]...", input.Id, input.NombreNuevo); var bannerToUpdate = Repository.SingleOrDefault(banner => banner.Id == input.Id); if (bannerToUpdate == null) { var exception = new Exception($"No se pudo encontrar el banner con el id: [{input.Id}]."); Log.Error(exception, EXCEPTION_MESSAGE_TEMPLATE, exception.Message); HandleErrors(bannerResponse, exception, 404); return(bannerResponse); } bannerToUpdate.Nombre = input.NombreNuevo; bannerToUpdate.Base64 = input.Base64Nuevo; var updatedBanner = Repository.Update(bannerToUpdate); bannerResponse.Banner = updatedBanner; bannerResponse.StatusCode = 200; Log.Information("Actualizado con exito el banner con Id: [{Id}] con nuevo nombre [{NewTitle}].", input.Id, input.NombreNuevo); } catch (Exception exception) { Log.Error(exception, EXCEPTION_MESSAGE_TEMPLATE, exception.Message); HandleErrors(bannerResponse, exception); } return(bannerResponse); }
public BannerResponse Execute(int id) { var bannerResponse = new BannerResponse(); try { Log.Information("Eliminando el Banner por Id:[{Id}]...", id); var toDelete = Repository.SingleOrDefault(banner => banner.Id == id); if (toDelete == null) { var exception = new Exception($"Banner no encontrado por Id:[{id}]."); Log.Error(exception, EXCEPTION_MESSAGE_TEMPLATE, exception.Message); HandleErrors(bannerResponse, exception, 404); } else { Repository.Delete(toDelete); bannerResponse.StatusCode = 200; Log.Information("Banner eliminado [{NewName}] por Id:[{Id}].", toDelete.Nombre, toDelete.Id); } } catch (Exception exception) { Log.Error(exception, "Error al elimnar el Banner. [{Message}].", exception.Message); HandleErrors(bannerResponse, exception); } return(bannerResponse); }
public BannerResponse Execute(CreateBannerInput input) { var bannerResponse = new BannerResponse(); try { Log.Information("Creando Banner Con nombre [{NewName}]...", input?.Nombre); byte[] imageBytes = Convert.FromBase64String(input?.Base64); BannerEntity bannerEntity = Mapper.Map <CreateBannerInput, BannerEntity>(input); bannerEntity.FechaCreacion = DateTime.Now; bannerResponse.Banner = Repository.Create(bannerEntity); bannerResponse.StatusCode = 200; Log.Information("Banner creado con el nombre [{NewName}] con el Id: [{Id}]", bannerResponse.Banner.Nombre, bannerResponse.Banner.Id); } catch (Exception exception) { Log.Error(exception, "Error al crear el Banner: [{NewName}].", input?.Nombre); HandleErrors(bannerResponse, exception); } return(bannerResponse); }
public IHttpActionResult GetBanner([FromUri] BannerRequestParameters reqParams) { var zone = db.Zones.Find(reqParams.ZoneID); if (zone == null) { return(NotFound()); } var query = (from p in db.Campaigns where p.Budget > 0 where p.BannerImageWidth <= zone.AdPlacementWidth where p.BannerImageHeight <= zone.AdPlacementHeight orderby p.Revenue descending select p).Take(1).ToList(); if (query.Count == 0) { return(NotFound()); } Campaign campaign = query.Single(); var baseUrl = Request.RequestUri.GetLeftPart(UriPartial.Authority); var clickUrl = baseUrl + "/api/ClickTracker?CampaignID=" + campaign.ID + "&ZoneID=" + reqParams.ZoneID; var imageHtml = "<img src='" + campaign.BannerImageUrl + "'/>"; BannerResponse response = new BannerResponse { CPC = campaign.Revenue, Currency = campaign.Currency, BannerWidth = campaign.BannerImageWidth, BannerHeight = campaign.BannerImageHeight, BannerHtml = "<a href='" + clickUrl + "'>" + imageHtml + "</a>" }; return(Ok(response)); }
public BannerResponse GetBanners() { BannerResponse bannerResponse = new BannerResponse(); try { bannerResponse.BannersImages = _repositoryBanner.Get().OrderByDescending(t => t.ID).Take(Constants.BANNERCOUNT).ToList(); if (bannerResponse != null) { bannerResponse.SetStatus(Constants.ResponseCode.SUCCESS); return(bannerResponse); } //b// 2kdk discorda gel daha hızlı ilerleriz bende cıkıcam az sonra bannerResponse.SetStatus(Constants.ResponseCode.SYSTEM_ERROR); return(bannerResponse); } catch (Exception ex) { bannerResponse.BannersImages = null; bannerResponse.SetStatus(Constants.ResponseCode.FAILED_ON_DB_PROCESS, ex.Message); return(bannerResponse); } }
public IActionResult GetBanners() { BannerResponse response = _service.GetBanners(); return(response.Code != (int)Constants.ResponseCode.SUCCESS ? StatusCode(500, response) : StatusCode(200, response)); }