public async Task<PostParse> ConvertSinglePostAsync(PostSql sqlPost) { if (sqlPost == null) { return null; } var parsePost = new PostParse() { Title = sqlPost.Title, Content = sqlPost.Content, Category = sqlPost.Category, IsBest = sqlPost.IsBest, Location = this.ConvertSingleLocation(sqlPost.Location) }; var parseImages = await Task.WhenAll(sqlPost.Images.Select(this.ConvertSingleImageAsync)); if (sqlPost.Images != null) { parseImages.ForEach(i => parsePost.AddToList("Images", i)); } if (sqlPost.Videos != null) { sqlPost.Videos.ForEach(v => parsePost.AddToList("Videos", this.ConvertSingleVideoAsync(v))); } return parsePost; }
public async Task<int> ConvertSinglePostAsync(PostViewModel sqlPost) { if (sqlPost == null) { return -1; } LocationSql location = new LocationSql(); var addres = await this.geolocationService.GetCurrentCivilAddresByLocationAsync(); if (addres != null) { location.Town = addres.Town; location.Country = addres.Country; } var images = new List<ImageSql>(); // TODO: ViewModel to SqLite model make it right way sqlPost.Images.ForEach(i => { var imgInfo = new ImageInfoSql() { OriginalName = i.ImageInfo.OriginalName, FileExstension = i.ImageInfo.FileExstension, ByteArrayContent = i.ImageInfo.ByteArrayContent }; var img = new ImageSql() { Title = i.Title, Description = i.Description, ImageInfo = imgInfo }; images.Add(img); }); var post = new PostSql() { Title = sqlPost.Title, Content = sqlPost.Content, Category = sqlPost.Category, IsBest = sqlPost.IsBest, Location = location, Images = images }; var result = await this.sqLiteService.AddNewPostAsync(post); return result; }
public async Task<int> AddNewPostAsync(PostSql newPost) { try { var connection = this.GetDbConnectionAsync(); await connection.InsertOrReplaceWithChildrenAsync(newPost, recursive: true); return newPost.Id; } catch (Exception ex) { var msg = ex.Message; return -1; } }