public IActionResult Create([FromBody] Mark mark)
        {
            if (mark == null)
            {
                return(BadRequest());
            }

            _context.Add(mark);

            return(new ObjectResult("ok"));
        }
예제 #2
0
        public ToDo CreateToDo(ToDo toDo)
        {
            _context.Add(toDo);
            _context.SaveChanges();

            return(toDo);
        }
        public async Task <IActionResult> Create([Bind("UserId,UserName")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
예제 #4
0
        public async Task <IActionResult> Create([Bind("CategoryId,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
예제 #5
0
        public async Task <IActionResult> Create([Bind("ToDoId,ToDoItem")] ToDo toDo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(toDo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(toDo));
        }
        public async Task <IActionResult> Create([Bind("ToDoId,ToDoName,UserId")] ToDo toDo)
        {
            if (ModelState.IsValid)
            {
                _context.Add(toDo);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["UserId"] = new SelectList(_context.Users, "UserId", "UserName", toDo.UserId);
            return(View(toDo));
        }
예제 #7
0
        public async Task <IActionResult> Create(DoList item)
        {
            if (ModelState.IsValid)
            {
                item.Date = DateTime.Now;
                context.Add(item);
                await context.SaveChangesAsync();

                TempData["Success"] = "The task has been added.";
                return(RedirectToAction("Index"));
            }

            return(View(item));
        }
예제 #8
0
        public string Add(Task model)
        {
            var todoContext = new ToDoDbContext();//create instance dbcontext

            try
            {
                todoContext.Add(model);    //save model to database
                todoContext.SaveChanges(); //commit save change
            }
            catch (Exception e)
            {
                return("Failed add data");   //return result
            }
            return("Successfully add data"); //return result
        }
예제 #9
0
        public async Task <IdentityResult> CreateAsync(User user, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            _context.Add(user);
            var affectedRows = await _context.SaveChangesAsync(cancellationToken);

            return(affectedRows > 0
                ? IdentityResult.Success
                : IdentityResult.Failed(new IdentityError()
            {
                Description = $"Could not create user {user.Username}."
            }));
        }
        public IActionResult Create(string title, string comments)
        {
            if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(comments))
            {
                return(RedirectToAction("Index"));
            }

            Task task = new Task(title, comments);

            using (ToDoDbContext db = new ToDoDbContext())
            {
                db.Add(task);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
예제 #11
0
        public IActionResult Create(Task newTask)
        {
            if (ModelState.IsValid)
            {
                using (var db = new ToDoDbContext())
                {
                    db.Add(newTask);
                    db.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                ViewData["Error"] = "Title and comments are required!";
                return(View());
            }
        }
예제 #12
0
 public Task Create(ToDoList toDoList)
 {
     _context.Add(toDoList);
     return(_context.SaveChangesAsync());
 }