Пример #1
0
        public IActionResult Profile(AddNoteBindingModel model)
        {
            using (var db = new SimpleMvcDbContext())
            {
                var user = db.Users.Find(model.UserId);
                var note = new Note
                {
                    Title   = model.Title,
                    Content = model.Content,
                };

                user.Notes.Add(note);
                db.SaveChanges();

                return(Profile(model.UserId));
            }
        }
Пример #2
0
        public IActionResult <UserProfileViewModel> Profile(AddNoteBindingModel model)
        {
            using (var context = new SimpleMvcDbContext())
            {
                var user = context.Users.Find(model.UserId);
                var note = new Note()
                {
                    Title   = model.Title,
                    Content = model.Content
                };

                user.Notes.Add(note);
                context.SaveChanges();
            }

            return(Profile(model.UserId));
        }
Пример #3
0
        public IActionResult <UserProfileViewModel> Profile(AddNoteBindingModel model)
        {
            using (var db = new NotesDbContext())
            {
                var user = db.Users.Find(model.UserId);

                Note note = new Note()
                {
                    Title   = model.Title,
                    Content = model.Content,
                };
                user.Notes.Add(note);
                db.SaveChanges();
            }

            return(Profile(model.UserId));
        }
Пример #4
0
        public IActionResult Profile(AddNoteBindingModel model)
        {
            using (var context = new NotesDbContext())
            {
                var user = context.Users.Find(model.UserId);

                var note = new Note
                {
                    Title   = model.Title,
                    Content = model.Content
                };

                user.Notes.Add(note);
                context.SaveChanges();
            }

            return(this.Profile(model.UserId));
        }
        public IActionResult <UserProfileViewModel> Profile(AddNoteBindingModel model)
        {
            using (SimpleMvcDbContext database = new SimpleMvcDbContext())
            {
                User user = database.Users.FirstOrDefault(u => u.Id == model.UserId);

                Note note = new Note
                {
                    Title   = model.Title,
                    Content = model.Content
                };

                user.Notes.Add(note);
                database.SaveChanges();
            }

            return(this.Profile(model.UserId));
        }
Пример #6
0
        public IViewable Profile(AddNoteBindingModel model)
        {
            using (var context = new NotesDbContext())
            {
                var note = new Note()
                {
                    Title   = model.Title,
                    Content = model.Content,
                    Owner   = context.Users.Find(model.UserId),
                };

                context.Notes.Add(note);
                context.Users.Find(model.UserId).Notes.Add(note);

                context.SaveChanges();
            };

            return(Profile(model.UserId));
        }
Пример #7
0
        public IActionResult Profile(AddNoteBindingModel model)
        {
            using (var db = new NotesDbContext())
            {
                User user = db.Users.FirstOrDefault(u => u.Id == model.UserId);

                Note note = new Note()
                {
                    Title   = model.Title,
                    Content = model.Content
                };

                user.Notes.Add(note);

                db.SaveChanges();
            }

            return(this.Profile(model.UserId));
        }
Пример #8
0
        public IActionResult Profile(AddNoteBindingModel model)
        {
            if (!this.IsValidModel(model))
            {
                return(View());
            }

            var note = new Note
            {
                UserId  = model.UserId,
                Title   = model.Title,
                Content = model.Content
            };

            using (var db = new SimpleAppDb())
            {
                db.Notes.Add(note);
                db.SaveChanges();
            }

            return(this.Profile(model.UserId));
        }
        public IActionResult <UserProfileViewModel> Profile(AddNoteBindingModel model)
        {
            using (var context = new NotesDbContext())
            {
                User user = context
                            .Users
                            .SingleOrDefault(u => u.Id == model.UserId);

                Note note = new Note
                {
                    Title   = model.Title,
                    Content = model.Content,
                    OwnerId = model.UserId,
                    Owner   = user
                };

                context.Notes.Add(note);
                context.SaveChanges();
            };

            return(Profile(model.UserId));
        }
Пример #10
0
        public IActionResult Profile(AddNoteBindingModel bindingModel)
        {
            if (!this.IsValidModel(bindingModel))
            {
                this.Model["error"] = "Form is not valid!";
                return(Profile(bindingModel.UserId));
            }

            var note = new Note()
            {
                Title   = bindingModel.Title,
                Content = bindingModel.Content,
                UserId  = bindingModel.UserId
            };

            using (var db = new NotesDbContext())
            {
                db.Notes.Add(note);
                db.SaveChanges();
            }

            return(RedirectToAction($"/users/profile?id={bindingModel.UserId}"));
        }
Пример #11
0
        public IActionResult Profile(AddNoteBindingModel model)
        {
            if (!this.IsModelValid(model))
            {
                return(this.View());
            }

            using (AdvancedMvcDbContext database = new AdvancedMvcDbContext())
            {
                User user = database.Users.FirstOrDefault(u => u.Id == model.UserId);

                Note note = new Note
                {
                    Title   = model.Title,
                    Content = model.Content
                };

                user.Notes.Add(note);
                database.SaveChanges();
            }

            return(this.Profile(model.UserId));
        }
Пример #12
0
        public IActionResult Profile(AddNoteBindingModel model)
        {
            noteService.Create(model.Title, model.Content, model.UserId);

            return(this.Profile(model.UserId));
        }