예제 #1
0
 public void CreateNotebook()
 {
     if (App.UserId != 0)
     {
         var currentUser = context.Users.Where(u => u.Id == App.UserId).First(); //new User("Nombre", "Apellido", "Login", "pass"); // test only
         var newNotebook = new Notebook("New Notebook", currentUser);
         context.Notebooks.Add(newNotebook);
         context.SaveChanges();
         ReadNotebooks();
     }
 }
예제 #2
0
        public IActionResult <UserProfileViewModel> Profile(NoteAddBindingModel noteBindingModel)
        {
            UserProfileViewModel vm = null;

            using (NoteAppContext context = new NoteAppContext())
            {
                User user = context.Users.Include("Notes").SingleOrDefault(u => u.Id == noteBindingModel.UserId);
                user.Notes.Add(new Note()
                {
                    Title = noteBindingModel.Title, Content = noteBindingModel.Content
                });

                context.SaveChanges();

                vm = new UserProfileViewModel()
                {
                    UserId   = noteBindingModel.UserId,
                    Username = user.Username,
                    Notes    = user.Notes.Select(n => new NoteViewModel()
                    {
                        Title = n.Title, Content = n.Content
                    }).ToArray(),
                };
            }

            return(this.View(vm));
        }
 public void AdicionarNota(NotesSet note)
 {
     using (var conexao = new NoteAppContext())
     {
         conexao.Note.Add(note);
         conexao.SaveChanges();
     }
 }
 public void RemoverNota(int id)
 {
     using (var conexao = new NoteAppContext())
     {
         var note = new NotesSet {
             ID = id
         };
         conexao.Note.Attach(note);
         conexao.Note.Remove(note);
         conexao.SaveChanges();
     }
 }
예제 #5
0
        public IActionResult Register(UserRegisterBindingModel model)
        {
            using (NoteAppContext context = new NoteAppContext())
            {
                context.Users.Add(new User()
                {
                    Username = model.Username, Password = $"SECRET{model.Password}"
                });
                context.SaveChanges();
            }

            return(this.View("Home", "Index"));
        }
 public void AtualizarNote(NotesSet note)
 {
     using (var conexao = new NoteAppContext())
     {
         var result = conexao.Note.SingleOrDefault(b => b.ID == note.ID);
         if (result != null)
         {
             result.CH_Name        = note.CH_Name;
             result.CH_Description = note.CH_Description;
             result.DT_Creation    = note.DT_Creation;
             conexao.SaveChanges();
         }
     }
 }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new NoteAppContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <NoteAppContext> >())) {
                // Look for any notes.
                if (context.Note.Any())
                {
                    return;   // DB has been seeded
                }

                context.Note.AddRange(
                    new Note {
                    Title    = "IT 372 Midterm",
                    Contents = "Midterms coming up! Study time - review slides and reading. The test is on paper. Prepare early.",
                    DueDate  = DateTime.Parse("2019-11-1"),
                },

                    new Note {
                    Title    = "Biology Lab 3",
                    Contents = "Lab on Mitosis and Meiosis. Located on Main Campus, Room 301. Professor said to bring paper and pen to record the lab results. Remember to bring an apron.",
                    DueDate  = DateTime.Parse("2019-11-12"),
                },

                    new Note {
                    Title    = "Return library books",
                    Contents = "Borrowed a few books to learn more about aquatic life. Need to return by this date or get a $5.00 fine for each book. Do not forget!",
                    DueDate  = DateTime.Parse("2019-11-15"),
                },

                    new Note {
                    Title    = "Scholarship Banquet",
                    Contents = "RSVP for the banquet. Let my plus-one know about the date, time, and location. Business attire.",
                    DueDate  = DateTime.Parse("2019-11-20"),
                },

                    new Note {
                    Title    = "Software Development Lifecycle",
                    Contents = "Requirements > Analysis > Implementation > Verification > Maintenance (the longest, and most costly stage)"
                }
                    );
                context.SaveChanges();
            }
        }