public async Task <ActionResult <NoteItem> > PostNoteItem(NoteItem item)
        {
            _context.NoteItems.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetNoteItem), new { id = item.Id }, item));
        }
        public async Task <IActionResult> PutNote(long id, NoteDTO noteDTO)
        {
            if (id != noteDTO.id)
            {
                return(BadRequest());
            }

            var noteItem = await _context.Notes.FindAsync(id);

            if (noteItem == null)
            {
                return(NotFound());
            }

            noteItem.NoteContent = noteDTO.NoteContent;
            noteItem.NoteAuthor  = noteDTO.NoteAuthor;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NoteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 3
0
        public async Task <ActionResult <List> > PostList(List list)
        {
            _context.ListItems.Add(list);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetList), new { id = list.Id }, list));
        }
Esempio n. 4
0
        public async Task <ActionResult <Models.Note> > PostTodoItem(Models.Note note)
        {
            _context.Notes.Add(note);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTodoItem), new { id = note.Id }, note));
        }
Esempio n. 5
0
        public async Task <IActionResult> PutCategory([FromRoute] int id, [FromBody] Category category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != category.ID)
            {
                return(BadRequest());
            }

            _context.Entry(category).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CategoryExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 6
0
        public async Task <IActionResult> Create(FileCreateViewModel vm, string categoryLessonId, int uniCategoryId, int depCategoryId)
        {
            int userid         = Convert.ToInt32(HttpContext.Session.GetInt32("UserId"));
            var categoryid     = Convert.ToInt32(categoryLessonId);
            var ctrgCourseName = await _context.CategoryTable.FirstOrDefaultAsync(p => p.Id == categoryid);

            var ctrgUni = await _context.CategoryTable.FirstOrDefaultAsync(p => p.Id == uniCategoryId);

            var ctrgDep = await _context.CategoryTable.FirstOrDefaultAsync(p => p.Id == depCategoryId);

            var usr = await _context.UserTable.FirstOrDefaultAsync(p => p.Id == userid);

            if (vm.FilePath == null || vm.Title == null || categoryid == 0 || uniCategoryId == 0 || depCategoryId == 0 || usr == null)
            {
                return(Json(new { ok = false }));
            }
            else
            {
                File file = new File();
                file.CourseName  = ctrgCourseName.Name;
                file.Title       = vm.Title;
                file.Description = vm.Description;
                file.FilePath    = vm.FilePath;
                file.AddedUser   = usr;
                file.UploadDate  = DateTime.Now;
                file.Category    = ctrgCourseName;
                file.University  = ctrgUni.Name;
                file.Department  = ctrgDep.Name;
                _context.Add(file);
                await _context.SaveChangesAsync();

                return(Json(new { ok = true }));
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> PutNote(long id, Note note)
        {
            if (id != note.Id)
            {
                return(BadRequest());
            }

            _context.Entry(note).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NoteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 8
0
        public async Task <ActionResult <Note> > AddNote(Note note)
        {
            _context.Notes.Add(note);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetNote), new { id = note.Id }, note));
        }
        public async Task <IActionResult> PutNote([FromRoute] int id, [FromBody] Note note)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != note.NoteId)
            {
                return(BadRequest());
            }

            note.UpdatedOn = DateTime.Now;

            _context.Entry(note).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NoteExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetNote", new { id = note.NoteId }, note));
        }
Esempio n. 10
0
        public async Task <IActionResult> Register(string Name, string Surname, string University, string Department, string City, string Email, string Password, string ConfirmPassword)
        {
            var User = await _context.UserTable.FirstOrDefaultAsync(p => p.Email == Email);

            if (User != null)
            {
                ModelState.AddModelError("", "Bu E-mail'e ait bir hesap vardır ! Lütfen Tekrar Deneyiniz.");
            }
            else
            {
                if (Password == ConfirmPassword && Email != null && Name != null &&
                    Surname != null && University != null && Department != null && City != null)
                {
                    User   user1          = new User();
                    string hashedPassword = Helper.PasswordHelper.HashPassword(Password);
                    user1.City       = City;
                    user1.Department = Department;
                    user1.Email      = Email;
                    user1.Hash       = hashedPassword;
                    user1.Name       = Name;
                    user1.Surname    = Surname;
                    user1.University = University;
                    _context.Add(user1);
                    await _context.SaveChangesAsync();

                    return(Json(new { ok = true, newurl = Url.Action("Login") }));
                }
                else
                {
                    return(Json(new { ok = false, message = "Şifre veya Kullanıcı Adı Yanlış" }));
                    //ModelState.AddModelError("", "Tekrar Girilen Şifre Hatalı ! Lütfen Tekrar Deneyiniz.");
                }
            }
            return(View());
        }
Esempio n. 11
0
        public async Task <IActionResult> PostAsync([FromBody] Note note)
        {
            await _noteContext.Notes.AddAsync(note);

            await _noteContext.SaveChangesAsync();

            return(Ok());
        }
Esempio n. 12
0
        public async Task <IActionResult> Create([Bind("Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Esempio n. 13
0
        public async Task <ActionResult> Create([Bind(Include = "NoteId,NoteDescription,HaveDone")] Note note)
        {
            if (ModelState.IsValid)
            {
                db.Notes.Add(note);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(note));
        }
Esempio n. 14
0
        public async Task <IActionResult> Create([Bind("ID,Title,Notes,CreatedOn,CategoryId,UserId,IsDeleted")] Note note)
        {
            if (ModelState.IsValid)
            {
                _context.Add(note);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "ID", "ID", note.CategoryId);
            ViewData["UserId"]     = new SelectList(_context.Users, "ID", "ID", note.UserId);
            return(View(note));
        }
Esempio n. 15
0
        public async Task putnote(Note note)
        {
            await _context.Note.Include(x => x.labels).Include(x => x.checklists).ForEachAsync(x =>
            {
                if (x.Id == note.Id)
                {
                    x.Title     = note.Title;
                    x.PlainText = note.PlainText;
                    x.Pinned    = note.Pinned;

                    foreach (Labels templ in note.labels)
                    {
                        Labels a = x.labels.Find(y => y.Id == templ.Id);
                        if (a != null)
                        {
                            a.label = templ.label;
                        }
                        else
                        {
                            Labels lab = new Labels()
                            {
                                label = templ.label
                            };
                            x.labels.Add(lab);
                        }
                    }

                    foreach (CheckList tempc in note.checklists)
                    {
                        CheckList a = x.checklists.Find(y => y.Id == tempc.Id);
                        if (a != null)
                        {
                            a.checkList = tempc.checkList;
                            a.isChecked = tempc.isChecked;
                        }
                        else
                        {
                            CheckList ch = new CheckList()
                            {
                                checkList = tempc.checkList, isChecked = tempc.isChecked
                            };
                            x.checklists.Add(ch);
                        }
                    }
                }
            });

            await _context.SaveChangesAsync();
        }
Esempio n. 16
0
        public async Task <IActionResult> Index([FromBody] User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Users.Add(user);
            await _context.SaveChangesAsync();

            var link = Url.Link("UpdateUser", new { id = user.Id });
            var uri  = new Uri(link, UriKind.Absolute);

            return(Created(uri, user));
        }
Esempio n. 17
0
 public async Task <IActionResult> Change(int id, Note Note)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Note.LastChange = DateTime.Now.ToString("dd.MM.yyyy HH:mm");
             db.Update(Note);
             await db.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!NoteInfoExists(Note.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(Redirect("~/Notes/View/" + id));
     }
     return(Redirect("/"));
 }
        public async Task <ActionResult> ConfigureDeliveryProvider(string providerAssemblyQualifiedName, bool isEnabled,
                                                                   FormCollection form)
        {
            var provider = GetProvider(providerAssemblyQualifiedName);
            var settings = GetOrCreatePushNotificationDeliveryProviderSettings(provider);

            if (ModelState.IsValid)
            {
                if (settings == null)
                {
                    return(RedirectToAction("Index"));
                }
                // reflection to get the TryUpdateMethod
                var method =
                    GetType()
                    .GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy)
                    .First(m => m.Name == "TryUpdateModel" && m.IsGenericMethod && m.GetParameters().Count() == 1)
                    .MakeGenericMethod(provider.Configuration.GetType());

                if ((bool)method.Invoke(this, new[] { provider.Configuration }))//TryUpdateModel call
                {
                    settings.ProviderConfigurationData = JObject.FromObject(provider.Configuration);
                    settings.IsEnabled = isEnabled;
                    await NoteContext.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
            }
            return(View(settings));
        }
        public async Task <ActionResult <Note> > CreateNote([FromBody] Note note)
        {
            _context.Add(note);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetById", new { id = note.Id }, note));
        }
Esempio n. 20
0
        public async Task <IActionResult> Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await db.Users.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    // добавляем пользователя в бд
                    db.Users.Add(new User {
                        Email = model.Email, Password = model.Password
                    });
                    await db.SaveChangesAsync();

                    await Authenticate(model.Email); // аутентификация

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }
Esempio n. 21
0
        public async Task <IActionResult> SetForSlide(string place, string presenter, string slug, int number,
                                                      [FromBody] NoteDto note, CancellationToken ct)
        {
            var slideIdentifier = $"{place}/{presenter}/{slug}/{number}";
            var user            = User.FindFirstValue(DeckHubClaimTypes.Handle);

            var existingNote = await _context.Notes
                               .SingleOrDefaultAsync(n => n.UserHandle == user && n.SlideIdentifier == slideIdentifier, ct)
                               .ConfigureAwait(false);

            if (existingNote == null)
            {
                existingNote = new Note
                {
                    Public          = false,
                    SlideIdentifier = slideIdentifier,
                    UserHandle      = user
                };
                _context.Notes.Add(existingNote);
            }

            existingNote.NoteText  = note.Text;
            existingNote.Timestamp = DateTimeOffset.UtcNow;
            await _context.SaveChangesAsync(ct).ConfigureAwait(false);

            return(Accepted());
        }
Esempio n. 22
0
        public async Task <IActionResult> Index([FromBody] UserNote note)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Notes.Add(note);
            await _context.SaveChangesAsync();

            note.User = await _context.Users.SingleOrDefaultAsync(t => t.Id == note.UserId);

            var link = Url.Link("UpdateNote", new { id = note.Id });
            var uri  = new Uri(link, UriKind.Absolute);

            return(Created(uri, note));
        }
Esempio n. 23
0
        public Task AddAsync(Note note)
        {
            //context.Notes.Add(note);
            context.Notes.Attach(note);

            for (int k = 0; k < 10; k++)
            {
                Note note1 = new Note()
                {
                    Title = note.Title + k.ToString(), Content = note.Content
                };

                context.Notes.Add(note1);
            }

            return(context.SaveChangesAsync());
        }
        public async Task <bool> Handle(CreateNotebookCommand command, CancellationToken cancellationToken)
        {
            // TODO: validate that a notebook doesn't already exist
            Notebook notebook = new Notebook(command.Name);

            _noteContext.Notebooks.Add(notebook);

            int records = await _noteContext.SaveChangesAsync(cancellationToken);

            return(records == 1);
        }
        public UnitTest1()
        {
            var dbBuilder = new DbContextOptionsBuilder <NoteContext>();

            dbBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new NoteContext(dbBuilder.Options);

            _context = context;
            _context.Note.AddRange(TestNoteInitial);
            _context.SaveChangesAsync();

            _controller = new NotesController(_context);
        }
Esempio n. 26
0
        public async Task <IActionResult> Create(
            [Bind("Email,Name,CreatedOn")] User user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(user);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                //Log the error (uncomment ex variable name and write a log.
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(user));
        }
Esempio n. 27
0
        public async Task <IActionResult> PutNotes([FromRoute] int id, [FromBody] Note notes)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != notes.ID)
            {
                return(BadRequest());
            }
            var user     = _context.Users.Find(notes.User.ID);
            var category = _context.Categories.Find(notes.Category.ID);

            notes.User     = user;
            notes.Category = category;

            _context.Entry(notes).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NotesExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Esempio n. 28
0
        }// brackets

        public async Task <bool> PutNote(Note note)
        {
            bool flag = false;
            //Func<Note, Note> FuncToUpdateNote(Note A);

            Note element = await _context.Note.Include(x => x.CheckList).Include(x => x.Label).SingleAsync(x => x.Id == note.Id);

            if (element != null)
            {
                flag            = true;
                element.Message = note.Message;
                element.Pinned  = note.Pinned;
                element.Title   = note.Title;
                _context.Label.RemoveRange(element.Label);
                element.Label.AddRange(note.Label);
                _context.CheckList.RemoveRange(element.CheckList);
                element.CheckList.AddRange(note.CheckList);
            }
            if (flag)
            {
                await _context.SaveChangesAsync();
            }
            return(flag);
        }
Esempio n. 29
0
        public async Task <List <NoteEntity> > GetNotes()
        {
            List <NoteEntity> list = new List <NoteEntity>();

            using (var context = new NoteContext())
            {
                if (!context.Notes.Any())
                {
                    for (int i = 0; i < 10; i++)
                    {
                        context.Notes.Add(new NoteEntity {
                            Date = DateTime.Now, Description = "Notes Descriptiom", Name = "Note" + i
                        });
                        context.SaveChangesAsync();
                    }
                }
                list = await context.Notes.ToListAsync();
            }
            return(list);
        }
Esempio n. 30
0
        public async Task <IActionResult> DeleteConfirmed(int id)
        {
            var noteToDelete = await _context.Notes.FirstOrDefaultAsync(n => n.ID == id);

            if (noteToDelete == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            try
            {
                _context.Notes.Remove(noteToDelete);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            catch (DbUpdateException)
            {
                return(RedirectToAction(nameof(Delete), new { id = id, saveChangesError = true }));
            }
        }