예제 #1
0
        public async Task <string> ProcessLinkDelete(long linkId)
        {
            LinkQueue q;

            try
            {
                q = await db.LinkQueue.SingleAsync(p => p.Id == linkId);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            if (q == null)
            {
                return("Job not in Queue");
            }

            //NoteFile notefile = await db.NoteFile.SingleAsync(p => p.Id == q.LinkedFileId);
            //string notefilename = notefile.NoteFileName;

            HttpClient MyClient = new HttpClient
            {
                BaseAddress = new Uri(q.BaseUri)
            };

            LinkDeleteModel delModel = new LinkDeleteModel()
            {
                baseGuid = q.LinkGuid
            };

            HttpResponseMessage resp3;

            try
            {
                resp3 = MyClient.PostAsync("api/ApiLinkD",
                                           new ObjectContent(typeof(LinkDeleteModel), delModel, new JsonMediaTypeFormatter()))
                        .GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            string result3 = resp3.Content.ReadAsStringAsync().GetAwaiter().GetResult();

            return(result3);
        }
        public async Task <string> DeleteLinkNote(LinkDeleteModel guid)
        {
            try
            {
                NoteHeader nh = await _context.NoteHeader.SingleOrDefaultAsync(p => p.LinkGuid == guid.baseGuid);

                if (nh == null || nh.LinkGuid != guid.baseGuid)
                {
                    return("No note to delete");
                }

                try
                {
                    // check for acceptance

                    NoteFile file = await _context.NoteFile.SingleAsync(p => p.Id == nh.NoteFileId);

                    if (file == null)
                    {
                        return("Target file does not exist");
                    }

                    if (!await AccessManager.TestLinkAccess(_context, file, ""))
                    {
                        return("Access Denied");
                    }
                }
                catch
                { // ignore
                }

                await NoteDataManager.DeleteNote(_context, nh);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return("Ok");
        }