private async Task <Kiosko_Promocion_Detalle> RetrieveKiosko_Promocion_Detalle(string codigoPromocion) { Logger.Log(string.Format("Descargando Kiosko Promociones Detalle (Id:{0})(CodigoPromocion:{1})", _idSync, codigoPromocion), Category.Info, Priority.Low); using (var client = new HttpClient()) { client.BaseAddress = new Uri(_webSyncServerAddress); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue( "Basic", Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(_apipwd))); try { HttpResponseMessage response = await client.GetAsync(string.Format("api/kiosko_promociones/{0}.json", codigoPromocion)); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsAsync <Object>(); Kiosko_Promocion_Detalle promocionDetalleWeb = Newtonsoft.Json.JsonConvert.DeserializeObject <Kiosko_Promocion_Detalle>(content.ToString()); Logger.Log(string.Format("Kiosko Promocion Detalle (Id:{0})(CodigoPromocion:{1}) descargado con exito.", _idSync, codigoPromocion), Category.Info, Priority.Low); return(promocionDetalleWeb); } return(null); } catch (HttpRequestException e) { Logger.Log(string.Format("Error descargando Kiosko Promocion Detalle (Id:{0})(CodigoPromocion{1}): {2}", _idSync, codigoPromocion, e.InnerException.Message), Category.Info, Priority.Low); return(null); } } }
private void UpdatePromocionComercial(Kiosko_Promocion_Detalle promocion) { using (var repository = new EnteComercialRepository()) { repository.AddOrUpdatePromocion(promocion); } Uri webpath; //Imagen Small if (!String.IsNullOrEmpty(promocion.ImagenSmallUrl.card.url)) { webpath = new Uri("file://localhost" + promocion.ImagenSmallUrl.card.url); if (webpath.IsFile) { string filename = System.IO.Path.GetFileName(webpath.LocalPath); string inputfilepath = AppDomain.CurrentDomain.BaseDirectory + "media\\" + filename; if (!System.IO.File.Exists(inputfilepath)) { //descargo DownloadFileFTP(promocion.ImagenSmallUrl.card.url, inputfilepath); } } } //Imagen if (!String.IsNullOrEmpty(promocion.ImagenUrl.banner.url)) { webpath = new Uri("file://localhost" + promocion.ImagenUrl.banner.url); if (webpath.IsFile) { string filename = System.IO.Path.GetFileName(webpath.LocalPath); string inputfilepath = AppDomain.CurrentDomain.BaseDirectory + "media\\" + filename; if (!System.IO.File.Exists(inputfilepath)) { //descargo DownloadFileFTP(promocion.ImagenUrl.banner.url, inputfilepath); } } } }
public void AddOrUpdatePromocion(Kiosko_Promocion_Detalle dto) { if (dto == null) return; var enteComercial = (from q in db.EnteComercials.Include("ListOfPromocions.ListOfPromocionCupons") where (q.Codigo == dto.ClienteCodigo) select q).FirstOrDefault(); if (enteComercial == null) return; var promocion = (from q in enteComercial.ListOfPromocions where (q.Codigo == dto.Codigo) select q).FirstOrDefault(); if (promocion == null) { var newPromocion = new Promocion() { Codigo = dto.Codigo, Descripcion = dto.Descripcion, Detalles = dto.Detalles, DetallesBig = dto.DetallesBig, Condiciones = dto.Condiciones, IsActivo = true }; DateTime outDate; if (DateTime.TryParse(dto.Inicio, out outDate)) newPromocion.FechaInicio = outDate; if (DateTime.TryParse(dto.Fin, out outDate)) newPromocion.FechaFin = outDate; newPromocion.Vigencia = Int32.Parse(dto.Vigencia); newPromocion.ImagenSmallUrl = dto.ImagenSmallUrl.card.ToFileName(); newPromocion.ImagenUrl = dto.ImagenUrl.banner.ToFileName(); if (dto.Limite != null) { newPromocion.CuponesPorUsuario = int.Parse(dto.Limite); } newPromocion.ListOfPromocionCupons = new List<PromocionCupon>(); foreach (var item in dto.Kiosko_Promociones) { var newCupon = new PromocionCupon() { CodigoCanjeo = item.Codigo, RemoteId = item.ID, }; newPromocion.ListOfPromocionCupons.Add(newCupon); } enteComercial.ListOfPromocions.Add(newPromocion); } else { promocion.Descripcion = dto.Descripcion; promocion.Detalles = dto.Detalles; promocion.DetallesBig = dto.DetallesBig; promocion.Condiciones = dto.Condiciones; DateTime outDate; if (DateTime.TryParse(dto.Inicio, out outDate)) promocion.FechaInicio = outDate; if (DateTime.TryParse(dto.Fin, out outDate)) promocion.FechaFin = outDate; promocion.Vigencia = Int32.Parse(dto.Vigencia); promocion.ImagenSmallUrl = dto.ImagenSmallUrl.card.ToFileName(); promocion.ImagenUrl = dto.ImagenUrl.banner.ToFileName(); if (dto.Limite != null) { promocion.CuponesPorUsuario = int.Parse(dto.Limite); } if (promocion.ListOfPromocionCupons != null) { foreach (var item in dto.Kiosko_Promociones) { var cupon = (from q in promocion.ListOfPromocionCupons where (q.RemoteId == item.ID) select q).FirstOrDefault(); if (cupon == null) { var newCupon = new PromocionCupon() { CodigoCanjeo = item.Codigo, RemoteId = item.ID, }; promocion.ListOfPromocionCupons.Add(newCupon); } } } } db.SaveChanges(); }