private void upload_Click(object sender, EventArgs e) { using (var localDb = new NoteContext()) { // Find notes that are not uploaded var newNotes = localDb.Notes .Where(n => !n.IsUploaded) .ToList(); // Upload to remote database using (var remoteDb = new NoteContext(_remoteDatabaseOptions)) { remoteDb.Database.EnsureCreated(); remoteDb.Notes.AddRange(newNotes); remoteDb.SaveChanges(); } // Mark as uploaded in local database newNotes.ForEach(n => n.IsUploaded = true); localDb.SaveChanges(); MessageBox.Show($"Uploaded {newNotes.Count} notes."); LoadExistingNotes(); } }
private void addNote_Click(object sender, RoutedEventArgs e) { using (var db = new NoteContext()) { var note = new Note { text = noteText.Text, created = DateTime.Now }; db.notes.Add(note); db.SaveChanges(); notes.ItemsSource = db.notes.ToList(); } }
private void Save_Click(object sender, RoutedEventArgs e) { var note = new Note { Created = DateTime.Now, Text = Note.Text }; using (var db = new NoteContext()) { db.Notes.Add(note); db.SaveChanges(); } Note.Text = string.Empty; }
private void save_Click(object sender, EventArgs e) { var note = new Note { Created = DateTime.Now, Text = this.note.Text }; using (var db = new NoteContext()) { db.Notes.Add(note); db.SaveChanges(); } noteBindingSource.Insert(0, note); this.note.Text = string.Empty; }
public ActionResult Index(ApplicationPushNotificationSetting settings, string siteRootUrl) { var dbSetting = NoteContext.TicketDeskPushNotificationSettings; if (ModelState.IsValid && TryUpdateModel(dbSetting)) { NoteContext.SaveChanges(); DomainContext.TicketDeskSettings.ClientSettings.Settings["DefaultSiteRootUrl"] = siteRootUrl.TrimEnd('/'); DomainContext.SaveChanges(); } ViewBag.CurrentRootUrl = GetCurrentRootUrl(); ViewBag.SiteRootUrl = GetRootUrlSetting(); return(View(dbSetting)); }
/// <summary> /// Question 添加 /// </summary> /// <param name="question">传递的question表的实体模型</param> /// <returns></returns> private IActionResult Create(Question question) { question.QuestionGuid = Guid.NewGuid(); question.Ctime = DateTime.Now; question.Version = Guid.NewGuid(); noteContext.Question.Add(question); int result = noteContext.SaveChanges(); if (result == 1) { return(Ok()); } else { return(NotFound("添加失败")); } }
public UnitTest1() { var host = new TestServer( new WebHostBuilder() .UseEnvironment("Testing") .UseStartup <Startup>() ); _context = host.Host.Services.GetService(typeof(NoteContext)) as NoteContext; _client = host.CreateClient(); _context.Note.AddRange(TestNoteProper1); _context.Note.AddRange(TestNoteProper2); _context.Note.AddRange(TestNoteDelete); _context.SaveChanges(); }
public ActionResult AddNote(Note note) { if (note != null) { note.UserId = User.Identity.GetUserId(); note.CreationTime = DateTime.Now; db.Notes.Add(note); db.SaveChanges(); return(new HttpStatusCodeResult(200)); } else { return(HttpNotFound()); } //return View("~/Views/Home/Index.cshtml"); /* if (note != null) * { * db.Notes.Add(note); * db.SaveChanges(); * return View(); * } * return HttpNotFound();*/ }
public UnitTest1() { var builder = new WebHostBuilder() .UseEnvironment("Testing") .UseStartup <Startup>(); TestServer testServer = new TestServer(builder); _client = testServer.CreateClient(); _context = testServer.Host.Services.GetRequiredService <NoteContext>(); dbnote.Add(note); dbnote.Add(note2); _context.Note.Add(note); _context.Note.Add(note2); _context.SaveChanges(); }
public static void Initialize(NoteContext context) { if (!context.Note.Any()) { context.Note.AddRange( new Note { Title = "Приветствуем вас в iNote!", Desc = "Это тестовая заметка, она создается автоматически. Попробуйте ее изменить", Color = "secondary", LastChange = DateTime.Now.ToString("dd.MM.yyyy hh:mm") } ); context.SaveChanges(); } }
private void PromptDelete_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Вы точно хотите удалить напоминание?", "notes", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { using (NoteContext db = new NoteContext()) { PromptModels promptModel = db.Prompts.Where(n => n.ID == Prompt.ID).FirstOrDefault(); db.Prompts.Remove(promptModel); db.SaveChanges(); } } Content = new HomePage(1); }
public async Task <IActionResult> BeginUpload() { //当前方法,单个上传文件限制为128m //获取当前用户 Guid currentUserGuid = Guid.Parse((from claim in HttpContext.User.Claims where claim.Type == "guid" select claim.Value).FirstOrDefault()); if (currentUserGuid == default) { return(NotFound("找不到用户关联信息")); } //获取当前用户家目录,在win为“我的文档”,linux默认为/home/{username} var homePath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); var files = Request.Form.Files; var guidFileName = Guid.NewGuid().ToString(); var storagePath = Path.Combine(Directory.CreateDirectory(Path.Combine(homePath, "userUploads")).FullName, guidFileName + Path.GetExtension(files[0].FileName)); try { using (var stream = new FileStream(storagePath, FileMode.CreateNew)) { await files[0].CopyToAsync(stream); } } catch (IOException) { return(Ok(new { Success = false, Message = "文件IO错误" })); } UploadFile upLoadFile = new UploadFile() { FileGuid = Guid.NewGuid(), UserGuid = currentUserGuid, LocalFilePath = storagePath, Ctime = DateTime.Now, }; noteContext.UploadFile.Add(upLoadFile); noteContext.SaveChanges(); return(Ok(new { Success = true, UploadGuid = guidFileName })); }
public ActionResult <string> Get([Required] string hash) { using (var db = new NoteContext(_dbConnectionString)) { var note = db.Notes.FirstOrDefault(x => x.Hash == hash); if (note == null) { return(NotFound()); } db.Notes.Remove(note); db.SaveChanges(); return(note.NoteString); } }
private void NoteDelete_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = MessageBox.Show("Вы точно хотите удалить заметку?", "notes", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { using (NoteContext db = new NoteContext()) { NoteModels noteModel = db.Notes.Where(n => n.ID == noteModels.ID).FirstOrDefault(); db.Notes.Remove(noteModel); db.SaveChanges(); } } Content = new HomePage(); }
public IntegrationTest() { var host = new TestServer( new WebHostBuilder() .UseEnvironment("Testing") .UseStartup <Startup>() ); _context = host.Host.Services.GetService(typeof(NoteContext)) as NoteContext; _client = host.CreateClient(); List <Note> TestNoteProper1 = new List <Note> { new Note() { Title = "Title-1-Deletable", text = "Message-1-Deletable", checklist = new List <CheckList>() { new CheckList() { Check = "checklist-1", isChecked = true }, new CheckList() { Check = "checklist-2", isChecked = false } }, labels = new List <Labels>() { new Labels() { label = "Label-1-Deletable" }, new Labels() { label = "Label-2-Deletable" } }, Pinned = true } }; _context.Note.AddRange(TestNoteProper1); _context.Note.AddRange(TestNoteDelete); _context.SaveChanges(); }
public ActionResult Index(ApplicationPushNotificationSetting settings, string siteRootUrl) { var dbSetting = NoteContext.TicketDeskPushNotificationSettings; if (ModelState.IsValid && TryUpdateModel(dbSetting)) { NoteContext.SaveChanges(); DomainContext.TicketDeskSettings.ClientSettings.Settings["DefaultSiteRootUrl"] = siteRootUrl.TrimEnd('/'); DomainContext.SaveChanges(); ViewBag.Saved = true; } ViewBag.CurrentRootUrl = GetCurrentRootUrl(); ViewBag.SiteRootUrl = GetRootUrlSetting(); Task.Delay(500).ContinueWith(t => System.Web.HttpRuntime.UnloadAppDomain()).ConfigureAwait(false); return(View(dbSetting)); }
public void AddNote(string noteString) { var addNoteController = new AddNoteController(_config); string hash = addNoteController.Add(noteString).Value; using (var db = new NoteContext(dataBaseConnection)) { var note = db.Notes.FirstOrDefault(x => x.Hash == hash); if (note != null) { Assert.AreEqual(note.NoteString, noteString); db.Notes.Remove(note); db.SaveChanges(); } } }
static void Main(string[] args) { using (var db = new NoteContext()) { var note1 = new Note("Today we learned about strings and databaeses.", "DotNet", "Databases", DateTime.Now, 1); db.Notes.Add(note1); var count = db.SaveChanges(); Console.WriteLine("{0} records saved to database", count); Console.WriteLine(); Console.WriteLine("All Notes in database:"); foreach (var note in db.Notes) { Console.WriteLine(" - {0}", note.ToString()); } } }
private void CreateNewNote_Click(object sender, RoutedEventArgs e) { if (tbTextNote.Text == "") { MessageBox.Show("Попытка создать пустую заметку.", "notes", MessageBoxButton.OK); } else { using (NoteContext db = new NoteContext()) { NoteModels noteModels = new NoteModels { CreationDate = DateTime.Now, NameNote = tbNameNote.Text, TextNote = tbTextNote.Text, TagsNote = cbTagsNote.Text }; db.Notes.Add(noteModels); db.SaveChanges(); } Content = new HomePage(); } }
public ActionResult <string> Add([Required][FromForm] string noteString) { string noteStringSanitized = new HtmlSanitizer().Sanitize(noteString); if (string.IsNullOrWhiteSpace(noteStringSanitized)) { return(BadRequest()); } using (var db = new NoteContext(_dbConnectionString)) { var note = new Note(Guid.NewGuid().ToHashString(), noteStringSanitized); db.Notes.Add(note); db.SaveChanges(); return(note.Hash); } }
private void upload_Click(object sender, EventArgs e) { using (var localDb = new NoteContext()) { // Find notes that are not uploaded var newNotes = localDb.Notes .Where(n => !n.IsUploaded) .ToList(); // TODO Upload to remote database var connectionString = ConfigurationManager.ConnectionStrings["RemoteDatabase"].ConnectionString; // Mark as uploaded in local database newNotes.ForEach(n => n.IsUploaded = true); localDb.SaveChanges(); MessageBox.Show($"Uploaded {newNotes.Count} notes."); LoadExistingNotes(); } }
private void CreateNewTag_Click(object sender, RoutedEventArgs e) { if (tbNameTag.Text[0] != '#' && tbNameTag.Text[1] != ' ') { MessageBox.Show("Неверный формат ввода.", "notes", MessageBoxButton.OK); } else if (tbNameTag.Text.Remove(0, 2) == "") { MessageBox.Show("Попытка добавить пустой тег.", "notes", MessageBoxButton.OK); } else { using (NoteContext db = new NoteContext()) { TagsModels tagsModels = new TagsModels { NameTags = tbNameTag.Text }; db.Tags.Add(tagsModels); db.SaveChanges(); } Content = new HomePage(2); } }
private void NoteSave_Click(object sender, RoutedEventArgs e) { if (cbTagsNote.Text == "") { cbTagsNote.Text = "не задано"; } if (tbNameNote.Text != noteModels.NameNote || tbTextNote.Text != noteModels.TextNote || cbTagsNote.Text != noteModels.TagsNote) { using (NoteContext db = new NoteContext()) { NoteModels noteModel = db.Notes.Where(n => n.ID == noteModels.ID).FirstOrDefault(); if (tbNameNote.Text != noteModels.NameNote) { noteModel.NameNote = tbNameNote.Text; } if (tbTextNote.Text != noteModels.TextNote) { noteModel.TextNote = tbTextNote.Text; } if (cbTagsNote.Text != noteModels.TagsNote) { noteModel.TagsNote = cbTagsNote.Text; } noteModel.CreationDate = DateTime.Now; db.SaveChanges(); } MessageBoxResult result = MessageBox.Show("Изменения успешно сохранены", "notes", MessageBoxButton.OK); } Content = new HomePage(); }
public void AddNote(Model.Note N) { _dbContext.Notes.Add(N); _dbContext.SaveChanges(); }
// POST api/note public void Post(Note value) { dataContext.Notes.Add(value); dataContext.SaveChanges(); }
public bool Save() { return(_context.SaveChanges() >= 0); }
public IntelligenceQueue(Guid queueGuid, Guid currentUser, NoteContext db) : base(queueGuid, currentUser, db) { #warning 此处不应该硬编码,未来修改时拆分至其他项目 Guid questionnaireGuid = Guid.Parse("b546b709-2b2b-4f6e-9f1f-64f281de8d5b"); Questionnaire qn = (from questionnaire in db.Questionnaire where questionnaire.Version != Guid.Empty where questionnaire.QuestionnaireGuid == questionnaireGuid orderby questionnaire.Ctime select questionnaire).First(); UserInformationRecord user = db.UserInformation.First(x => x.UserGuid == currentUser); List <Guid> questionList = JsonConvert.DeserializeObject <List <Guid> >(qn.Question); if (user.UserGender == UserInformationRecord.Gender.Man) { //如果为男性,移除白带异常问题 questionList.Remove(Guid.Parse("23E317C9-D691-402E-8249-C0E4D3ED78D0")); } else { //如果为女性,移除阴囊潮湿问题 questionList.Remove(Guid.Parse("A6C1DBC2-233D-4FA8-927B-8BAED0F709B3")); } DateTime today = DateTime.Now;//兼容多次测试 //查找出用户已经答过的问题 IQueryable <Guid> answeredQuestions = from answer in db.Answer where answer.Userid == currentUser where answer.Ctime.Date == today.Date//兼容多次测试 where answer.Mtime != DateTime.MinValue where questionList.Contains(answer.QuestionGuid) select answer.QuestionGuid; if (answeredQuestions.Any()) { //移除 foreach (Guid answeredQuestion in answeredQuestions) { questionList.Remove(answeredQuestion); //Console.WriteLine("移除了一个记录:" + answeredQuestion); } } //Console.WriteLine($"该用户还有{questionList.Count}道题没有完成"); IOrderedQueryable <Question> questionRecords = from s in db.Question where s.Version != Guid.Empty orderby s.Ctime descending select s; foreach (Guid a in questionList) { QuestionQueue queues = new QuestionQueue { QueueGuid = guid, QuestionVersion = questionRecords.First(x => x.QuestionGuid == a).Version, QueueUser = base.user, Ctime = DateTime.Now }; db.QuestionQueue.Add(queues); } db.QuestionQueue.Add(new QuestionQueue { QueueGuid = guid, QuestionVersion = Guid.Parse("CB849EFF-6C6F-433B-BB46-535570D6158B"), Ctime = DateTime.Now, QueueUser = base.user, DynamicContent = JsonConvert.SerializeObject(new Conclusion { Link = $"Result/{base.user.ToString()}", Title = "您的体质似乎是这样的……", Options = new Dictionary <string, BooleanOption.Option> { { "Left", new BooleanOption.Option { Text = "哦?" } }, { "Right", new BooleanOption.Option { Text = "我想知道" } }, } }) }); db.SaveChanges(); }