public async Task <bool> UpsertNearByMePromotion(NearByMePromotion promotion) { StringBuilder ImagesXml = new StringBuilder("<ImageList>"); foreach (NearByMePromotionImage item in promotion.ImagesXml) { ImagesXml.Append("<Image>" + "<ImageCaption>" + item.imageCaption + "</ImageCaption>" + "<ImagePath>" + item.imagePath + "</ImagePath>" + "<FeaturedImage>" + item.featuredImage + "</FeaturedImage>" + "</Image>"); } ImagesXml.Append("</ImageList>"); StringBuilder PromotionPackagesXml = new StringBuilder("<PromotionPackages>"); foreach (NearByMeUserPromotionsPackage item in promotion.PromotionPackagesXml) { PromotionPackagesXml.Append( "<PromotionPackage>" + "<PackageId>" + item.packageId + "</PackageId>" + "<promotionId>" + item.promotionId + "</promotionId>" + "<runUntill>" + item.runUntill + "</runUntill>" + "</PromotionPackage>"); } PromotionPackagesXml.Append("</PromotionPackages>"); return(await System.Threading.Tasks.Task.Run(() => _dbManager.UpsertNearByMePromotion(promotion.promotionId, promotion.username, promotion.description, promotion.status, promotion.audienceMaxAge, promotion.audienceMinAge, promotion.locations, promotion.audienceGender, promotion.audienceInterests, ImagesXml.ToString(), PromotionPackagesXml.ToString()))); }
public async Task <bool> UpsertPromotion(NearByMePromotion promotion) { StringBuilder ImagesXml = new StringBuilder("<ImageList>"); foreach (NearByMePromotionImage item in promotion.ImagesXml) { string str = item.imagePath; var ext = item.imagePath.Substring(item.imagePath.LastIndexOf(".")); // Construct file save path //string newfileName = httpPostedFile.FileName.Remove(httpPostedFile.FileName.Length - 4, 4) + "_u_" + Guid.NewGuid() + "."+ext; // string newfileName = httpPostedFile.FileName.Substring(0, httpPostedFile.FileName.LastIndexOf(".")) + "_u_" + Guid.NewGuid() + "." + ext; // var ex = str.Substring(str.Length - 3); str = str.Substring(str.LastIndexOf('/') + 1); str = str.Substring(0, str.IndexOf("_u_")) /*+ ".jpg"*/; str = str + ext; ImagesXml.Append("<Image>" + "<ImageCaption>" + item.imageCaption + "</ImageCaption>" + "<ImagePath>" + item.imagePath + "</ImagePath>" + "<FeaturedImage>" + item.featuredImage + "</FeaturedImage>" + "<ImageName>" + str + "</ImageName>" + "</Image>"); } ImagesXml.Append("</ImageList>"); return(await System.Threading.Tasks.Task.Run(() => _dbManager.UpsertPromotion(promotion.username, promotion.description, promotion.status, ImagesXml.ToString()))); }
public async Task <bool> UpsertPromotionNew(NearByMePromotion promotion) { StringBuilder ImagesXml = new StringBuilder("<ImageList>"); foreach (NearByMePromotionImage item in promotion.ImagesXml) { //string str = item.imagePath; //str = str.Substring(str.LastIndexOf('/') + 1); //str = str.Substring(0, str.IndexOf("_u_")) /*+ ".jpg"*/; //var ex = str.Substring(str.Length - 3); //str = str + "." + ex; ImagesXml.Append("<Image>" + "<ImageCaption>" + item.imageCaption + "</ImageCaption>" + "<ImagePath>" + item.imagePath + "</ImagePath>" + "<FeaturedImage>" + item.featuredImage + "</FeaturedImage>" + "<ImageName>" + item.ImageName + "</ImageName>" + "</Image>"); } ImagesXml.Append("</ImageList>"); return(await System.Threading.Tasks.Task.Run(() => _dbManager.UpsertPromotion(promotion.username, promotion.description, promotion.status, ImagesXml.ToString()))); }
public async Task <HttpResponseMessage> UpdateNearByMePromotionWithPath([FromBody] LibNeeo.NearByMe.NearByMePromotion promotion) { try { LogRequest(promotion); if (!ModelState.IsValid) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } bool operationCompleted = await System.Threading.Tasks.Task.Run(() => nearByMePromotionManager.UpsertNearByMePromotion(promotion)); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (ApplicationException applicationException) { return(Request.CreateErrorResponse((HttpStatusCode)Convert.ToInt16(applicationException.Message), NeeoDictionaries.HttpStatusCodeDescriptionMapper[Convert.ToInt16(applicationException.Message)])); } catch (Exception exception) { Logger.LogManager.CurrentInstance.ErrorLogger.LogError(System.Reflection.MethodBase.GetCurrentMethod().GetType(), exception.Message, exception); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }