示例#1
0
 public IActionResult Create(ToDoItems item)
 {
     if (ModelState.IsValid)
     {
         _context.ToDoItems.Add(item);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(item));
 }
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Department,Username,Email,Password,ConfirmPassword")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index", "Home"));
            }

            return(View(user));
        }
示例#3
0
        public ActionResult Create([Bind(Include = "Id,UserName,Email,Password,PasswordCheck")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
示例#4
0
        public ActionResult Create([Bind(Include = "Title")] Task task)
        {
            if (ModelState.IsValid)
            {
                db.Tasks.Add(task);
                db.SaveChanges();
                return(JsonSuccess(new { task = task }));
            }

            return(JsonError("Model is invalid"));
        }
        public ActionResult Create([Bind(Include = "Id,Description,DueDate,Completed,UserId")] Task task)
        {
            if (ModelState.IsValid)
            {
                db.Tasks.Add(task);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.UserId = new SelectList(db.Users, "Id", "UserName", task.UserId);
            return(View(task));
        }
        public ActionResult Create([Bind(Include = "Id,UserId,Description,DueDate,TimeLeft,Complete")] Task task)
        {
            if (ModelState.IsValid)
            {
                db.Tasks.Add(task);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            //left in here to show as example of structure in future
            //ViewBag.UserId = new SelectList(db.Users, "Id", "FirstName", task.UserId);
            return(View(task));
        }
示例#7
0
 public ActionResult Create(Tasks task)
 {
     if (ModelState.IsValid)
     {
         _taskListDB.Tasks.Add(task);
         _taskListDB.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View());
     }
 }
        public ActionResult Create([Bind(Include = "Id,Title,Content,Severity,DeadLine")] Task task)
        {
            if (ModelState.IsValid)
            {
                task.CreatedAt = DateTime.Now;
                task.UpdatedAt = DateTime.Now;
                db.Tasks.Add(task);
                db.SaveChanges();
                TempData["flash"] = "タスクを追加しました。";
                return(RedirectToAction("Index"));
            }

            return(View(task));
        }
示例#9
0
        public void Delete(int id)
        {
            var task = TaskListContext.Tasks.First(t => t.Id == id);

            TaskListContext.Tasks.Remove(task);
            TaskListContext.SaveChanges();
        }
示例#10
0
        public Task Create(Task task)
        {
            var createdTask = TaskListContext.Tasks.Add(task).Entity;

            TaskListContext.SaveChanges();
            return(createdTask);
        }
示例#11
0
 public IActionResult AddNewTask(Tasks newtask)
 {
     if (ModelState.IsValid)
     {
         _context.Tasks.Add(newtask);
         _context.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
示例#12
0
        public IActionResult Post([FromBody] IEnumerable <YinActivity> activities)
        {
            if (_db.YinActivities.Count() != 0)
            {
                return(BadRequest(new
                {
                    error = "Cannot POST with existing DB records"
                }));
            }

            DateTime dt = DateTime.Now;

            foreach (var act in activities)
            {
                act.AssignmentCd    = NEW;
                act.CreatedDateTime = dt;
            }
            _db.YinActivities.AddRange(activities);
            _db.SaveChanges();

            return(CreatedAtAction(nameof(Post), activities));
        }
        public void Delete(int id)
        {
            var taskList = TaskListContext.TaskLists.Where(t => t.Id == id).Include(t => t.Tasks).First();

            if (taskList.Tasks != null)
            {
                foreach (var task in taskList.Tasks)
                {
                    TaskListContext.Tasks.Remove(task);
                }
            }
            TaskListContext.Remove(taskList);
            TaskListContext.SaveChanges();
        }
示例#14
0
        public IActionResult Upsert(int id)
        {
            Task = new TaskList();
            if (ModelState.IsValid)
            {
                Task.TaskName = this.Request.Form["TaskName"];
                Task.Id       = id;
                if (Task.Id == 0)
                {
                    Task.TaskStatus  = "To Do";
                    Task.TotalHours  = "0";
                    Task.DateCreated = DateTime.Now;
                    _db.Tasks.Add(Task);
                }
                else
                {
                    _db.Update(Task);
                }
                _db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(Task));
        }
        public TaskList Create(TaskList taskList)
        {
            var createdTasks = new List <Task>();

            foreach (var task in taskList.Tasks)
            {
                var createdTask = TaskListContext.Tasks.Add(task).Entity;
                createdTasks.Add(createdTask);
            }
            taskList.Tasks = createdTasks;
            var createdTaskList = TaskListContext.TaskLists.Add(taskList).Entity;

            TaskListContext.SaveChanges();
            return(createdTaskList);
        }
示例#16
0
        public IActionResult Index()
        {
            _taskListContext.Database.Migrate();

            if (!_taskListContext.TaskLists.Any())
            {
                _taskListContext.TaskLists.Add(new TaskList()
                {
                    Name = "test"
                });
                _taskListContext.SaveChanges();
            }

            return(View());
        }
        public IActionResult AddTask(EachTask newTask)
        {
            newTask.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (ModelState.IsValid)
            {
                _context.Task.Add(newTask);
                _context.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View());
            }
        }
        public TaskList Update(TaskList taskList)
        {
            var tasksFromDb = TaskListContext.Tasks.Where(t => t.TaskListId == taskList.Id);

            //are there tasks which were previously in tasklist but no longer?
            var tasksToRemove = new List <Task>();

            foreach (var taskFromDb in tasksFromDb)
            {
                if (!taskList.Tasks.Any(t => t.Id == taskFromDb.Id))
                {
                    tasksToRemove.Add(taskFromDb);
                }
            }
            TaskListContext.Tasks.RemoveRange(tasksToRemove);

            var tasks = taskList.Tasks;

            taskList.Tasks = new List <Task>();
            foreach (var task in tasks)
            {
                if (TaskListContext.Tasks.Any(t => t.Id == task.Id))
                {
                    taskList.Tasks.Add(TaskListContext.Tasks.First(t => t.Id == task.Id));
                }
                else
                {
                    taskList.Tasks.Add(TaskListContext.Tasks.Add(task).Entity);
                }
            }

            TaskListContext.Update(taskList);

            TaskListContext.SaveChanges();
            return(taskList);
        }
示例#19
0
 public int SaveChanges()
 {
     return(Db.SaveChanges());
 }
示例#20
0
 public void Save()
 {
     db.SaveChanges();
 }
示例#21
0
        public void Add(Task task)
        {
            context.Tasks.Add(task);

            context.SaveChanges();
        }
示例#22
0
 public void Save()
 {
     _databaseContext.SaveChanges();
 }
示例#23
0
 /// <summary>
 /// Implementação do método que adiciona um registro.
 /// </summary>
 /// <param name="obj">Classe que esta sendo inserido o registro.</param>
 public void Add(TEntity obj)
 {
     _db.Set <TEntity>().Add(obj);
     _db.SaveChanges();
 }
示例#24
0
 public void Save()
 {
     _context.SaveChanges();
 }
示例#25
0
 public bool Commit()
 {
     return(_context.SaveChanges() > 0);
 }
示例#26
0
 public void Add(TEntity entity)
 {
     Db.Set <TEntity>().Add(entity);
     Db.SaveChanges();
 }