public async Task <int> HandleImageCommit(int userId, Dictionary <Stream, string> streams, string[][] megaTags, int albumId, string privacy, string notes) { Models.Tag[] applyTags = Array.Empty <Models.Tag>(); // Album[] applyAlbums = Array.Empty<Album>(); if (megaTags.Length > 0) { applyTags = await HandleTags(userId, megaTags).ConfigureAwait(false); } //if (albums.Length > 0) // applyAlbums = await HandleAlbums(userId, albums).ConfigureAwait(false); using (var ctx = new PickPixDbContext(filePath)) { foreach (KeyValuePair <Stream, string> curPic in streams) { Picture pic = getPictureModel(curPic.Key, curPic.Value); pic.Notes = notes; pic.Privacy = privacy; pic.UserId = userId; int curPicId = await this.AddItemAsync(pic).ConfigureAwait(false); if (curPicId == 0) { System.Diagnostics.Debug.WriteLine("========================================= Failed to save picture"); return(0); } //var tracker = await ctx.Pictures.UpdateItemAsync(curPic){ //} foreach (Models.Tag curTag in applyTags) { var tracker = await ctx.PictureTags.AddAsync(new PictureTag { PictureId = curPicId, TagId = curTag.TagId }).ConfigureAwait(false); await ctx.SaveChangesAsync().ConfigureAwait(false); } if (albumId > 0) { await ctx.PictureAlbums.AddAsync(new PictureAlbum { PictureId = curPicId, AlbumId = albumId }).ConfigureAwait(false); } } await ctx.SaveChangesAsync().ConfigureAwait(false); } return(0); }
public async Task <int> AddItemAsync(Album album) { try { using (var ctx = new PickPixDbContext(this.filePath)) { album.CreatedAt = DateTime.Now; album.UpdatedAt = DateTime.Now; album.Active = true; album.UserId = this.UserId; var findExistingAlbum = await ctx.Albums.Where(s => s.Name.ToLower() == album.Name.ToLower()).SingleOrDefaultAsync().ConfigureAwait(false); if (findExistingAlbum != null) { return(-1); } var tracker = await ctx.Albums.AddAsync(album).ConfigureAwait(false); await ctx.SaveChangesAsync().ConfigureAwait(false); } return(album.Id); } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(0); }
public async Task <bool> UpdateItemAsync(Album item) { bool result = false; try { using (var ctx = new PickPixDbContext(this.filePath)) { Album album = ctx.Albums.SingleOrDefault(A => A.Id == item.Id); if (album != null) { album.Name = item.Name; album.Description = item.Description; album.Privacy = item.Privacy; album.Active = item.Active; album.UpdatedAt = item.UpdatedAt; await ctx.SaveChangesAsync().ConfigureAwait(false); result = true; } } } catch (Exception) { throw; } return(result); }
public async Task <bool> UpdateItemAsync(Tag item) { bool result = false; try { using (var ctx = new PickPixDbContext(this.filePath)) { Tag tag = ctx.Tags.SingleOrDefault(A => A.TagId == item.TagId); if (tag != null) { tag.Name = item.Name; tag.TagType = item.TagType; tag.Updated = DateTime.Now; await ctx.SaveChangesAsync().ConfigureAwait(false); result = true; } } } catch (Exception) { throw; } return(result); }
public async Task <int> RegisterUser(User user) { try { using (var dbContext = new PickPixDbContext(filePath)) { var tracker = await dbContext.Users.AddAsync(user).ConfigureAwait(false); await dbContext.SaveChangesAsync().ConfigureAwait(false); } return(user.Id); } catch (Exception) { return(0); } }
public async Task <int> AddItemAsync(Picture picture) { bool result = false; try { using (var cxt = new PickPixDbContext(this.filePath)) { picture.Created = DateTime.Now; picture.Updated = DateTime.Now; cxt.Pictures.Add(picture); await cxt.SaveChangesAsync().ConfigureAwait(false); return(picture.Id); } } catch (Exception ex) { //To-Do Implement logging } return(0); }
public async Task <int> AddTagAsync(Models.Tag tag) { try { using (var dbContext = new PickPixDbContext(filePath)) { Tag findExistingTag = await dbContext.Tags.Where(s => (s.Name.ToLower() == tag.Name.ToLower()) && (s.TagType == tag.TagType)).FirstOrDefaultAsync().ConfigureAwait(false); if (findExistingTag != null) { return(findExistingTag.TagId); } var tracker = await dbContext.Tags.AddAsync(tag).ConfigureAwait(false); await dbContext.SaveChangesAsync().ConfigureAwait(false); } return(tag.TagId); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(0); }