示例#1
0
        /// <summary>
        /// Removes the specified note ids from the collection, and logs them in
        /// the graves table.
        /// </summary>
        /// <param name="noteIds">The list of note ids to remove.</param>
        /// <returns>The number of notes removed.</returns>
        public async Task <long> RemoveNotes(List <long> noteIds)
        {
            var notes = context.Notes
                        .Where(n => noteIds.Contains(n.ClientId) && n.UserId == collection.UserId);

            await LogRemovals(noteIds, GraveType.Note);

            context.RemoveRange(notes);

            long notesCount = notes.Count();

            await context.SaveChangesAsync();

            return(notesCount);
        }
示例#2
0
        /// <summary>
        /// Process media upload form client.
        /// </summary>
        /// <param name="changes">Used to upload client media files.</param>
        /// <returns>Returns the count of media files processed, and the current update sequence number.</returns>
        public async Task <IActionResult> UploadChanges([FromForm] UploadChanges changes)
        {
            ApplicationUser user = await userManager.GetUserAsync(HttpContext.User);

            MediaMeta meta = await context.MediaMeta.FirstOrDefaultAsync(m => m.User == user);

            if (meta == null)
            {
                meta = new MediaMeta
                {
                    User = user,
                    DirectoryModified        = DateTimeOffset.UtcNow.DateTime,
                    LastUpdateSequenceNumber = 0,
                };
            }

            long processedCount = await mediaSyncer.Upload(user.Id, changes.Data);

            meta.LastUpdateSequenceNumber += processedCount;

            context.MediaMeta.Update(meta);

            await context.SaveChangesAsync();

            return(Ok(new
            {
                data = new long[] { processedCount, meta.LastUpdateSequenceNumber },
                err = ""
            }));
        }