public async Task <IActionResult> Save(WebNote webNote) { var user = await _userManager.GetUserAsync(HttpContext.User); _webNoteService.CreateNote(webNote, user); return(Ok()); }
public void CreateNote(WebNote webNote, ApplicationUser user) { int nbrOfNotes = _context.WebNotes.Count(); //query list here .ToList apoi foloseste asta in forloop for (int i = 0; i < nbrOfNotes; i++) { var noteToModify = _context.WebNotes.FirstOrDefault(x => x.OrderIndex == i); if (noteToModify != null) { noteToModify.OrderIndex++; _context.WebNotes.Update(noteToModify); } } var file = new FileAttachment(); webNote.User = user; webNote.FileAttachment = file; webNote.hasFile = false; var toUpdate = _context.Users.FirstOrDefault(x => x.Id == user.Id); toUpdate.WebNotes.Add(webNote); toUpdate.FileAttachments.Add(file); _context.Update(toUpdate); _context.Add(webNote); _context.SaveChanges(); }
public IActionResult SendEmail(string email, WebNote note) { string loggedInEmail = User.Identity.Name; _webNoteService.SendEmail(note, loggedInEmail, email); return(Ok()); }
public async Task <IActionResult> UploadFileAttachment(WebNote noteToAttachTo, string file) { var note = noteToAttachTo; var fileSplit = file.Split(","[0]); var fileTypeHeaders = fileSplit[0]; var convertedFile = Convert.FromBase64String(fileSplit[1]); var user = await _userManager.GetUserAsync(HttpContext.User); _webNoteService.AddFileToNote(noteToAttachTo, convertedFile, fileTypeHeaders, user); return(Ok()); }
public void AddFileToNote(FileAttachment file, WebNote noteToAttachTo, ApplicationUser user) { //Add new file to DB _context.FileAttachments.Add(file); //Add it to the user user.FileAttachments.Add(file); _context.Update(user); //Asign it to a webnote //var toUpdate = _context.WebNotes.FirstOrDefault(x => x.Id == noteToAttachTo.Id); noteToAttachTo.FileAttachment = file; noteToAttachTo.FileId = file.Id; noteToAttachTo.hasFile = true; _context.Update(noteToAttachTo); _context.SaveChanges(); }
public void AddFileToNote(WebNote noteToAttachTo, byte[] fileData, string fileType, ApplicationUser user) { //Create a file / Add it to DB var newFileAttachment = new FileAttachment(); newFileAttachment.User = user; newFileAttachment.Name = "File Attachment"; newFileAttachment.WebNote = noteToAttachTo; newFileAttachment.FileData = fileData; newFileAttachment.Type = fileType; _context.FileAttachments.Add(newFileAttachment); //Add it to the user user.FileAttachments.Add(newFileAttachment); _context.Update(user); //Asign it to a webnote var toUpdate = _context.WebNotes.FirstOrDefault(x => x.Id == noteToAttachTo.Id); toUpdate.FileAttachment = newFileAttachment; _context.Update(toUpdate); _context.SaveChanges(); }
public async Task DeleteFile(int fileId) { //Removing file from DB FileAttachment theFile = _context.FileAttachments.FirstOrDefault(x => x.Id == fileId); WebNote theNoteOfTheFile = _context.WebNotes.SingleOrDefault(x => x.FileId == fileId); //theNoteOfTheFile.FileId = 0; theNoteOfTheFile.hasFile = false; _context.Update(theNoteOfTheFile); theFile.URI = ""; theFile.Name = ""; theFile.Size = 0; _context.Update(theFile); _context.SaveChanges(); //Removing file from Azure CloudStorageAccount storageAccount = CloudStorageAccount.Parse(Environment.GetEnvironmentVariable("storageConnectionString")); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("files"); CloudBlockBlob blockBlob = container.GetBlockBlobReference(theFile.Name); await blockBlob.DeleteAsync(); }
void IWebNoteService.SendEmail(WebNote note, string loggedInEmail, string email) { var engine = EngineFactory.CreatePhysical(Path.Combine(_hostingEnvironment.ContentRootPath, "Templates", "Email")); var model = new { Sender = loggedInEmail, Title = note.Title, Color = note.Color, Content = note.Content, }; string result = engine.Parse("basic.cshtml", model); var message = new MimeMessage(); message.From.Add(new MailboxAddress("WebNotes", "*****@*****.**")); message.To.Add(new MailboxAddress(email, email)); message.Subject = "WebNote from " + loggedInEmail; message.Body = new TextPart("html") { Text = result }; using (var client = new SmtpClient()) { client.Connect("smtp.mailgun.org", 587, false); // Note: since we don't have an OAuth2 token, disable // the XOAUTH2 authentication mechanism client.AuthenticationMechanisms.Remove("XOAUTH2"); // Note: only needed if the SMTP server requires authentication client.Authenticate( Environment.GetEnvironmentVariable("emailClientUsername"), Environment.GetEnvironmentVariable("emailClientPassword")); client.Send(message); client.Disconnect(true); } // }
public IActionResult getSingleWebNote(int id) { WebNote webnote = _context.WebNotes.FirstOrDefault(x => x.Id == id); return(Json(webnote)); }