public async Task <NoteHeader> Create(Notes2021.Models.TextViewModel inputModel) { string authHeader = Request.Headers["authentication"]; string[] auths = authHeader.Split(','); IdentityUser me = await _userManager.FindByIdAsync(auths[1]); UserData appMe = await _context.UserData.SingleAsync(p => p.UserId == me.Id); if (String.Compare(auths[2], appMe.MyGuid, StringComparison.Ordinal) != 0) { return(null); } string userID = auths[1]; NoteAccess myAcc = await AccessManager. GetAccess(_context, userID, inputModel.NoteFileID, 0); if (!myAcc.Write) { return(null); } await _signInManager.SignInAsync(me, false); DateTime now = DateTime.Now.ToUniversalTime(); NoteHeader nheader = new NoteHeader() { LastEdited = now, ThreadLastEdited = now, CreateDate = now, NoteFileId = inputModel.NoteFileID, AuthorName = appMe.DisplayName, AuthorID = _userManager.GetUserId(User), NoteSubject = inputModel.MySubject, ResponseOrdinal = 0, ResponseCount = 0 }; if (inputModel.BaseNoteHeaderID == 0) { return(await NoteDataManager .CreateNote(_context, _userManager, nheader, inputModel.MyNote.Replace("\n", "<br />"), inputModel.TagLine, inputModel.DirectorMessage, true, false)); } NoteHeader bnh = await NoteDataManager.GetNoteHeader(_context, inputModel.BaseNoteHeaderID); nheader.BaseNoteId = bnh.Id; return(await NoteDataManager.CreateResponse(_context, _userManager, nheader, inputModel.MyNote, inputModel.TagLine, inputModel.DirectorMessage, true, false)); }
public async Task <NoteHeader> Edit(Notes2021.Models.TextViewModel inputModel) { string authHeader = Request.Headers["authentication"]; string[] auths = authHeader.Split(','); IdentityUser me = await _userManager.FindByIdAsync(auths[1]); UserData appMe = await _context.UserData.SingleAsync(p => p.UserId == me.Id); if (String.Compare(auths[2], appMe.MyGuid, StringComparison.Ordinal) != 0) { return(null); } string userID = auths[1]; NoteAccess myAcc = await AccessManager.GetAccess(_context, userID, inputModel.NoteFileID, 0); //TODO if (!myAcc.Write) { return(null); } await _signInManager.SignInAsync(me, false); DateTime now = DateTime.Now.ToUniversalTime(); NoteHeader oheader = await NoteDataManager .GetBaseNoteHeaderById(_context, inputModel.NoteID); if (oheader.AuthorID != userID) // must be a note this user wrote. { return(null); } oheader.LastEdited = now; oheader.ThreadLastEdited = now; oheader.NoteSubject = inputModel.MySubject; NoteContent oContent = await NoteDataManager .GetNoteContent(_context, oheader.NoteFileId, 0, oheader.NoteOrdinal, oheader.ResponseOrdinal); //TODO oContent.NoteBody = inputModel.MyNote; oContent.DirectorMessage = inputModel.DirectorMessage; return(await NoteDataManager .EditNote(_context, _userManager, oheader, oContent, inputModel.TagLine)); }