Ejemplo n.º 1
0
        public async Task <ActionResult <ListItem> > PostListItem(ListItem listItem)
        {
            _context.ListItems.Add(listItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetListItem", new { id = listItem.Id }, listItem));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> PostTodoItem([FromBody] TodoItem todoItem)
        {
            _context.TodoItems.Add(todoItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTodoItem), new { id = todoItem.Id }, todoItem));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> PutUser(int id, User user)
        {
            if (id != user.UserId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <TaskItem> > PostTaskItem(TaskItem taskItem)
        {
            _context.TaskItems.Add(taskItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetTaskItem", new { id = taskItem.Id }, taskItem));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> PutTodoItem(long id, TodoItem todoItem)
        {
            if (id != todoItem.Id)
            {
                return(BadRequest());
            }

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


            // Creo otro TodoListContext
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TodoItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> PutToDoListItem([FromRoute] long id, [FromBody] ToDoListItem toDoListItem)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != toDoListItem.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> PutToDoList(int id, ToDoList ToDoList)
        {
            if (id != ToDoList.ToDoListId)
            {
                return(BadRequest());
            }
            _context.Entry(ToDoList).State = EntityState.Modified;

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

            return(NoContent());
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create(ToDoItem toDoItem)
        {
            _context.ToDoItems.Add(toDoItem);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <ActionResult <PruebasTablas> > PostTodoItem(PruebasTablas todoItem)
        {
            _context.PruebaTabla.Add(todoItem);
            await _context.SaveChangesAsync();

            //return CreatedAtAction("GetTodoItem", new { id = todoItem.Id }, todoItem);
            return(CreatedAtAction(nameof(GetTodoItem), new { id = todoItem.Id }, todoItem));
        }
Ejemplo n.º 10
0
        public async Task <Person> AddPerson(Person person)
        {
            await _dbContext.Persons.AddAsync(person);

            await _dbContext.SaveChangesAsync();

            return(person);
        }
Ejemplo n.º 11
0
        public async Task <ToDoItem> AddToDo(ToDoItem todo)
        {
            todo.UserId = int.Parse(_user.GetValue(ClaimTypes.NameIdentifier));

            await _context.ToDoLists.AddAsync(todo);

            await _context.SaveChangesAsync();

            return(todo);
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Add([Bind("Id,Title,Description,Status")] ToDoList.Models.SomeTask SomeTask)
        {
            if (ModelState.IsValid)
            {
                _context.Add(SomeTask);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(SomeTask));
        }
        public async Task <IActionResult> Create(Item items)
        {
            if (ModelState.IsValid)
            {
                _context.Add(items);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(items));
        }
Ejemplo n.º 14
0
        public async Task <IActionResult> Create([Bind("Id,Description,DueDate,Complete,IdNetUsers")] TodoItem todoItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(todoItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["IdNetUsers"] = new SelectList(_context.TodoItem, "Id", "Description", todoItem.IdNetUsers);
            return(View(todoItem));
        }
        public async Task <IActionResult> PostToDo([FromBody] ToDoListItem todo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.ToDoListItems.Add(todo);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetToDo", new { id = todo.ID }, todo));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> AjaxCreate([Bind("Id,Description")] ToDoItem toDoItem)
        {
            toDoItem.IsDone = false;
            if (ModelState.IsValid)
            {
                _context.Add(toDoItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(PartialView("ToDoItemsTable", GetToDoItems()));
        }
Ejemplo n.º 17
0
        public async Task <Todo> AddItemAsync(Todo item)
        {
            if (_dbContext.Persons.AsNoTracking().FirstOrDefault(e => e.Pesel == item.PersonId) == null)
            {
                throw new ArgumentException("User with given pesel does not exist.");
            }
            await _dbContext.Todos.AddAsync(item);

            await _dbContext.SaveChangesAsync();

            _dbContext.Entry(item).Reference(c => c.Person).Load();
            return(item);
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            _logger.LogInformation("Register user.");
            if (ModelState.IsValid)
            {
                var user = await _context.Users.FirstOrDefaultAsync(u => u.Email == model.Email);

                if (user == null)
                {
                    await _context.Users.AddAsync(new User
                    {
                        FirstName   = model.FirstName,
                        LastName    = model.LastName,
                        DateOfBirth = model.DateOfBirth,
                        Email       = model.Email,
                        Password    = model.Password
                    });

                    await _context.SaveChangesAsync();

                    user = await _context.Users.FirstOrDefaultAsync(u => u.Email == model.Email);
                    await Authenticate(user.Email, user.Id);

                    return(RedirectToAction("Index", "Index"));
                }
                else
                {
                    _logger.LogWarning("Incorrect login or password.");
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }
        public async Task <IActionResult> SaveChangesNoteAsync(EditNoteViewModel editNoteViewModel)
        {
            var note = await _context.Notes.FindAsync(editNoteViewModel.Id);

            note.Header          = editNoteViewModel.Header;
            note.Text            = editNoteViewModel.Text;
            note.DateLastChanged = DateTime.Now;

            try
            {
                _context.Entry(note).State = EntityState.Modified;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!NoteExists(editNoteViewModel.Id))
                {
                    return(RedirectToAction("Index", "Index"));
                }

                throw;
            }

            return(RedirectToAction("Index", "Index"));
        }
Ejemplo n.º 20
0
        public async Task <ActionResult> Create(TodoList item)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (ModelState.IsValid)
            {
                item.UserId = userId;
                context.Add(item);
                await context.SaveChangesAsync();

                TempData["Success"] = "The item has been added!";

                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> SaveChangesReminderAsync(ReminderViewModel reminderViewModel)
        {
            var note = await _context.Reminders.FindAsync(reminderViewModel.Id);

            note.Header          = reminderViewModel.Header;
            note.Text            = reminderViewModel.Text;
            note.DateLastChanged = DateTime.Now;
            note.ReminderDate    = new DateTime(reminderViewModel.ReminderDate.Ticks);
            note.StatusNote      = reminderViewModel.StatusNote;

            try
            {
                _context.Entry(note).State = EntityState.Modified;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReminderExists(reminderViewModel.Id))
                {
                    return(RedirectToAction("Index", "Index"));
                }

                throw;
            }

            return(RedirectToAction("Index", "Index"));
        }
Ejemplo n.º 22
0
        public async Task <ActionResult <Services.TaskDetail> > DeleteTaskDetail(int id)
        {
            var taskDetail = await _context.ToDoList.FindAsync(id);

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

            _context.ToDoList.Remove(taskDetail);
            await _context.SaveChangesAsync();

            return(taskDetail);
        }
        public async Task <IActionResult> CreateNote(NoteViewModel noteViewModel)
        {
            if (noteViewModel.Header == null)
            {
                return(RedirectToAction("Index", "Index"));
            }

            _userid = Request.Cookies["userid"];
            var note = new Note()
            {
                Header          = noteViewModel.Header,
                Text            = noteViewModel.Text,
                IdUser          = new Guid(_userid),
                DateCreated     = DateTime.Now,
                DateLastChanged = DateTime.Now
            };
            await _context.Notes.AddAsync(note);

            await _context.SaveChangesAsync();


            return(RedirectToAction("Index", "Index"));
        }
Ejemplo n.º 24
0
        public async Task <ActionResult <Category> > AddCategory(Category category)
        {
            await _context.SaveChangesAsync();

            return(category);
        }
Ejemplo n.º 25
0
        public async Task <TaskDetail> SaveAsync(TaskDetail taskDetail)
        {
            await ToDoListContext.SaveChangesAsync();

            return(taskDetail);
        }
Ejemplo n.º 26
0
 public async Task <bool> SaveAsync()
 {
     return(await _context.SaveChangesAsync() >= 0);
 }
Ejemplo n.º 27
0
 public async Task SaveAsync()
 {
     await db.SaveChangesAsync();
 }
Ejemplo n.º 28
0
 public async Task Save()
 {
     await dbContext.SaveChangesAsync();
 }
Ejemplo n.º 29
0
 public async Task <bool> SaveAllAsync()
 {
     return((await _context.SaveChangesAsync()) > 0);
 }