public ActionResult GetNotebyId(string id) { _log.LogInformation("NOTE is inserted"); statsDPublisher.Increment("_NOTE_GETBYID_API"); string username = getUsername(); NOTES notes = _context.notes.Find(id); IEnumerable <Attachments> at = _context.attachments.AsEnumerable(); List <mAttachments> newat = new List <mAttachments>(); foreach (Attachments attachments in at) { if (attachments.noteID == notes.noteID) { mAttachments m = new mAttachments(); m.AID = attachments.AID; m.url = attachments.url; newat.Add(m); } } if (notes.EMAIL == username) { return(StatusCode(200, new{ ID = notes.noteID, Content = notes.content, Title = notes.title, Created_On = notes.created_on, last_updated_on = notes.last_updated_on, attachments = newat })); } else { return(StatusCode(401, new{ result = "Not Authorized" })); } }
public ActionResult GetNoteAttachmentbyId(string id) { string username = getUsername(); NOTES notes = _context.notes.Find(id); IEnumerable <Attachments> at = _context.attachments.AsEnumerable(); List <mAttachments> newat = new List <mAttachments>(); foreach (Attachments attachments in at) { if (attachments.noteID == notes.noteID) { mAttachments m = new mAttachments(); m.AID = attachments.AID; m.url = attachments.url; newat.Add(m); } } if (notes.EMAIL == username) { return(StatusCode(200, new{ attachments = newat })); } else { return(StatusCode(401, new{ result = "Not Authorized" })); } }
public ActionResult GetNotebyId(string id) { string username = getUsername(); NOTES notes = _context.notes.Find(id); if (notes != null) { IEnumerable <Attachments> at = _context.attachments.AsEnumerable(); List <mAttachments> newat = new List <mAttachments>(); foreach (Attachments attachments in at) { if (attachments.noteID == notes.noteID) { mAttachments m = new mAttachments(); m.AID = attachments.AID; m.url = attachments.url; newat.Add(m); } } if (notes.EMAIL == username) { return(StatusCode(200, new{ ID = notes.noteID, Content = notes.content, Title = notes.title, Created_On = notes.created_on, last_updated_on = notes.last_updated_on, attachments = newat })); } else { return(StatusCode(401, new{ result = "Not Authorized" })); } } else { return(StatusCode(401, new{ result = "Note Absent" })); } }
public ActionResult getNote() { IEnumerable <NOTES> notes = _context.notes.AsEnumerable(); List <NOTE> note = new List <NOTE>(); _log.LogInformation("Getting the node"); statsDPublisher.Increment("_NOTE_GET_API"); string username = getUsername(); IEnumerable <Attachments> at = _context.attachments.AsEnumerable(); foreach (NOTES item in notes) { if (item.EMAIL == username) { NOTE n = new NOTE(); n.noteID = item.noteID; n.content = item.content; n.created_on = item.created_on; n.title = item.title; n.last_updated_on = item.last_updated_on; List <mAttachments> newat = new List <mAttachments>(); foreach (Attachments attachment in at) { if (attachment.noteID == n.noteID) { mAttachments m = new mAttachments(); m.AID = attachment.AID; m.url = attachment.url; newat.Add(m); } } n.attachments = newat; note.Add(n); } } if (note.Capacity != 0) { IEnumerable <NOTE> newnote = note; string Json = JsonConvert.SerializeObject(newnote, Formatting.Indented); return(StatusCode(200, Json)); } else { return(StatusCode(200, new{ result = "You Don't have any notes!!! Sorry" })); } }
public ActionResult AttachImage(string id, IFormFile file) { var fileTransferUtility = new TransferUtility(s3Client); string fileName = (rand.ToString() + file.FileName); rand++; // var uniqueFileName = GetUniqueFileName(file.FileName); var filePath = Path.Combine(file.FileName); var uploads = Path.Combine(Directory.GetCurrentDirectory(), fileName); using (var stream = new FileStream(filePath, FileMode.Create)) { // fileTransferUtility.UploadAsync(stream,bucketName, keyName); file.CopyToAsync(stream); } fileTransferUtility.UploadAsync(uploads, bucketName, fileName); GetPreSignedUrlRequest request = new GetPreSignedUrlRequest(); request.BucketName = bucketName; request.Key = fileName; request.Expires = DateTime.Now.AddYears((2)); request.Protocol = Protocol.HTTP; string url = fileTransferUtility.S3Client.GetPreSignedURL(request); string username = getUsername(); // Console.WriteLine(arguments[1]); Console.WriteLine("Upload 1 completed"); if (file.Length > 0) { } NOTES note = _context.notes.Find(id); var Attachment = new Attachments { url = url, FileName = fileName, length = file.Length, noteID = note.noteID }; _context.Add(Attachment); _context.SaveChanges(); IEnumerable <Attachments> a1 = _context.attachments.AsEnumerable(); List <mAttachments> am = new List <mAttachments>(); string key = ""; foreach (Attachments at in a1) { if (at.noteID == id) { key = at.FileName; mAttachments mA = new mAttachments(); mA.AID = at.AID; mA.url = at.url; am.Add(mA); } } // fileTransferUtility.S3Client.DeleteObjectAsync(new Amazon.S3.Model.DeleteObjectRequest() { BucketName = bucketname, Key = key }); IEnumerable <mAttachments> newA = am; if (ModelState.IsValid) { var a11 = new mAttachments { AID = Attachment.AID, url = Attachment.url }; // string username = us.getUsername(); return(StatusCode(201, new{ a11 })); } else { var conflict = "Bad Request"; return(StatusCode(409, new{ result = conflict })); } }
public ActionResult createNotes(NOTES n, IFormFile file) { if (ModelState.IsValid) { _log.LogInformation("NOTE is inserted"); statsDPublisher.Increment("_NOTE_API"); var authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]); var credentialBytes = Convert.FromBase64String(authHeader.Parameter); var credentials = Encoding.UTF8.GetString(credentialBytes).Split(':'); var username = credentials[0]; var fileTransferUtility = new TransferUtility(s3Client); string fileName = (rand.ToString() + file.FileName); rand++; var uploads = Path.Combine(Directory.GetCurrentDirectory(), file.FileName); var filePath = Path.Combine(uploads); if (file.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) file.CopyToAsync(stream); } fileTransferUtility.UploadAsync(filePath, bucketName, fileName); GetPreSignedUrlRequest request = new GetPreSignedUrlRequest(); request.BucketName = bucketName; request.Key = fileName; request.Expires = DateTime.Now.AddYears(2); request.Protocol = Protocol.HTTP; string url = fileTransferUtility.S3Client.GetPreSignedURL(request); var Attachment = new Attachments { url = url, FileName = fileName, length = file.Length, noteID = n.noteID }; _context.Add(Attachment); mAttachments att = new mAttachments(); att.AID = Attachment.AID; att.url = Attachment.url; _context.SaveChanges(); var notes = new NOTES { EMAIL = username, attachments = Attachment, content = n.content, created_on = DateTime.Now, title = n.title, last_updated_on = DateTime.Now }; _context.Add(notes); // _context.Add(Attachment); _context.SaveChanges(); IEnumerable <Attachments> at = _context.attachments.AsEnumerable(); List <mAttachments> newat = new List <mAttachments>(); foreach (Attachments attachment in at) { if (attachment.noteID == n.noteID) { mAttachments m = new mAttachments(); m.AID = attachment.AID; m.url = attachment.url; newat.Add(m); } } string Json = JsonConvert.SerializeObject(notes, Formatting.Indented); return(StatusCode(201, new{ noteId = notes.noteID, content = n.content, created_on = DateTime.Now, title = n.title, last_updated_on = DateTime.Now, attachments = att })); } else { var conflict = "Bad Request"; return(StatusCode(409, new{ result = conflict })); } }
public ActionResult AttachImage(string id, IFormFile file) { var fileTransferUtility = new TransferUtility(s3Client); string fileName = (file.FileName + rand.ToString()); rand++; // var uniqueFileName = GetUniqueFileName(file.FileName); var filePath = Path.Combine(file.FileName); var uploads = Path.Combine(Directory.GetCurrentDirectory(), file.FileName); using (var stream = new FileStream(uploads, FileMode.Create)) { // fileTransferUtility.UploadAsync(stream,bucketName, keyName); file.CopyToAsync(stream); } string username = getUsername(); Console.WriteLine("Upload 1 completed"); if (file.Length > 0) { } NOTES note = _context.notes.Find(id); var Attachment = new Attachments { url = uploads, FileName = file.FileName, length = file.Length, noteID = note.noteID }; _context.Add(Attachment); _context.SaveChanges(); IEnumerable <Attachments> a1 = _context.attachments.AsEnumerable(); List <mAttachments> am = new List <mAttachments>(); foreach (Attachments at in a1) { if (at.noteID == id) { mAttachments mA = new mAttachments(); mA.AID = at.AID; mA.url = at.url; am.Add(mA); } } IEnumerable <mAttachments> newA = am; if (ModelState.IsValid) { var a11 = new mAttachments { AID = Attachment.AID, url = Attachment.url }; // string username = us.getUsername(); return(StatusCode(201, new{ a11 })); } else { var conflict = "Bad Request"; return(StatusCode(409, new{ result = conflict })); } }
public ActionResult createNotes(NOTES n, IFormFile file) { if (ModelState.IsValid) { var authHeader = AuthenticationHeaderValue.Parse(Request.Headers["Authorization"]); var credentialBytes = Convert.FromBase64String(authHeader.Parameter); var credentials = Encoding.UTF8.GetString(credentialBytes).Split(':'); var username = credentials[0]; string fileName = (file.FileName + rand.ToString()); rand++; // var uniqueFileName = GetUniqueFileName(file.FileName); var uploads = Path.Combine(Directory.GetCurrentDirectory(), fileName); var filePath = Path.Combine(uploads); if (file.Length > 0) { using (var stream = new FileStream(filePath, FileMode.Create)) file.CopyToAsync(stream); } var Attachment = new Attachments { url = uploads, FileName = file.FileName, length = file.Length, noteID = n.noteID }; _context.Add(Attachment); mAttachments att = new mAttachments(); att.AID = Attachment.AID; att.url = Attachment.url; _context.SaveChanges(); var notes = new NOTES { EMAIL = username, attachments = Attachment, content = n.content, created_on = DateTime.Now, title = n.title, last_updated_on = DateTime.Now }; _context.Add(notes); // _context.Add(Attachment); _context.SaveChanges(); IEnumerable <Attachments> at = _context.attachments.AsEnumerable(); List <mAttachments> newat = new List <mAttachments>(); foreach (Attachments attachment in at) { if (attachment.noteID == n.noteID) { mAttachments m = new mAttachments(); m.AID = attachment.AID; m.url = attachment.url; newat.Add(m); } } string Json = JsonConvert.SerializeObject(notes, Formatting.Indented); // var a1 = new mAttachments{AID = Attachment.AID ,url=Attachment.url}; // string username = us.getUsername(); return(StatusCode(201, new{ noteId = notes.noteID, content = n.content, created_on = DateTime.Now, title = n.title, last_updated_on = DateTime.Now, attachments = att })); } else { var conflict = "Bad Request"; return(StatusCode(409, new{ result = conflict })); } }