Esempio n. 1
0
        public IActionResult Register(RegisterBindingModel model)
        {
            if (!this.IsValidModel(model))
            {
                return(this.View());
            }
            using (var db = new NotesDbContext())
            {
                if (db.Users.Any(u => u.Username == model.Username))
                {
                    throw new ArgumentException("Username already taken!");
                }

                var user = new User()
                {
                    Username = model.Username,
                    Password = model.Password
                };

                db.Add(user);
                db.SaveChanges();
            }

            return(this.View());
        }
        public async Task <IActionResult> Create([Bind("Id,HomeFileId,HomeFileName,RemoteFileName,RemoteBaseUri,AcceptFrom,SendTo")] LinkedFile linkedFile)
        {
            if (ModelState.IsValid)
            {
                if (!linkedFile.RemoteBaseUri.EndsWith('/'))
                {
                    linkedFile.RemoteBaseUri = linkedFile.RemoteBaseUri.TrimEnd(' ') + "/";
                }

                LinkProcessor lp = new LinkProcessor(_context);

                if (await lp.Test(linkedFile.RemoteBaseUri))
                {
                    _context.Add(linkedFile);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
                else
                {
                    return(RedirectToAction(nameof(Error)));
                }
            }
            return(View(linkedFile));
        }
Esempio n. 3
0
        /// <summary>
        /// Implementation of CreateNote handler to create a new note
        /// </summary>
        /// <returns></returns>
        public async Task <IActionResult> OnPostCreateNoteAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            dbContext.Add(Note);

            await dbContext.SaveChangesAsync();

            return(RedirectToPage("/Notes"));
        }
Esempio n. 4
0
        public IActionResult Post([FromBody] Note model)
        {
            try
            {
                context.Add(model);
                context.SaveChanges();

                return(Created($"/api/notes/{model.Id}", model));
            }
            catch (Exception ex) {
                return(BadRequest("Failed to post a note"));
            }
        }
Esempio n. 5
0
        public void Create(string username, string password)
        {
            using (var db = new NotesDbContext())
            {
                var user = new User
                {
                    Username = username,
                    Password = password
                };

                db.Add(user);

                db.SaveChanges();
            }
        }
Esempio n. 6
0
        public void Create(string title, string content, int userId)
        {
            using (var db = new NotesDbContext())
            {
                var note = new Note
                {
                    OwnerId = userId,
                    Title   = title,
                    Content = content
                };

                db.Add(note);
                db.SaveChanges();
            }
        }
Esempio n. 7
0
 public void AddNote(Note note)
 {
     ctx.Add(note);
     ctx.SaveChanges();
 }