Beispiel #1
0
        /// <summary>
        /// 删除一个事项
        /// </summary>
        /// <param name="itemId"></param>
        public void DeleteItem(int itemId)
        {
            Items item = _ctx.Items.SingleOrDefault(p => p.ItemId == itemId);

            _ctx.Items.Remove(item);
            _ctx.SaveChanges();
        }
Beispiel #2
0
        //THIS IS WHAT WE DID IN CLASS

        public ActionResult ToggleComplete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Task task = db.Tasks.Find(id); //pulling the id number

            if (id == null)
            {
                return(HttpNotFound());
            }
            if (task.IsComplete)         //checking if the box is checked
            {
                task.IsComplete = false; //if so, unchecking it
            }
            else
            {
                task.IsComplete = true; //if not, checking it
            }

            db.SaveChanges();                  //saving changes to the database

            return(RedirectToAction("Index")); //essentially refreshing the page with the new results
        }
 public ActionResult Create(Item item)
 {
     //Add() & SaveChanges() update DbSet and sync the changes to the database represented by DbContext
     _db.Items.Add(item); //Add() is run on DbSet property (_db.Items in this case)
     _db.SaveChanges();   //SaveChanges() is run on DbContext itself
     return(RedirectToAction("Index"));
 }
        public Relationship Create(Relationship classification)
        {
            var newRelationship = db.Relationships.Add(classification);

            db.SaveChanges();
            return(newRelationship);
        }
Beispiel #5
0
        public ToDoTask Create(ToDoTask toDoTask)
        {
            var newToDoTask = db.ToDoTasks.Add(toDoTask);

            db.SaveChanges();
            return(newToDoTask);
        }
        public IHttpActionResult PutToDoList(int id, ToDoListApp.ToDoList toDoList)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            db.Entry(toDoList).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ToDoListExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #7
0
        public IHttpActionResult PutItem(int id, Item item)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            db.Entry(item).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #8
0
        public Picture Create(Picture picture)
        {
            var newPicture = db.Pictures.Add(picture);

            db.SaveChanges();
            return(newPicture);
        }
Beispiel #9
0
        public Classification Create(Classification classification)
        {
            var newClassification = db.Classifications.Add(classification);

            db.SaveChanges();
            return(newClassification);
        }
Beispiel #10
0
        public ActionResult Index(string name, int id, string mode)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (mode == "new")
                    {
                        db.ToDoList.Add(new Models.ToDoList()
                        {
                            TaskName = name, TaskDate = DateTime.UtcNow, Priority = null
                        });
                        db.SaveChanges();
                    }
                    else if (mode == "edit")
                    {
                        var Nid = db.ToDoList.Find(id);
                        Nid.TaskName = name;
                        Nid.TaskDate = DateTime.UtcNow;
                        Nid.Priority = null;
                        db.SaveChanges();
                    }

                    return(PartialView("Display", db.ToDoList.ToList()));
                }
                //ViewBag.mode = "new";
            } catch (Exception) {
                return(null);
            }

            return(null);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            var thisItem = _db.Items.FirstOrDefault(items => items.ItemId == id);

            _db.Items.Remove(thisItem);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #12
0
 public void AddTask(Task task)
 {
     using (ctx)
     {
         ctx.Tasks.Add(task);
         ctx.SaveChanges();
     }
 }
        internal static void EditGoal(Goal goalEdited)
        {
            Goal goal = db.Goals.Find(goalEdited.Id);

            goal.Name         = goalEdited.Name;
            goal.Note         = goalEdited.Note;
            goal.DateTimeToDo = goalEdited.DateTimeToDo;
            db.SaveChanges();
        }
Beispiel #14
0
        private void UpdateStatus(User source, ToDoTask task, STATUS status)
        {
            task.Status = status;
            this.Update(null, task);

            var log = new DbLog(DateTime.Now, ACTION_TARGET.TASK, ACTION.CHANGE_STATUS, CHANGE_FIELD.TITLE, source.Id, task.Id, task.Title, EnumConverter.Convert(status), null);

            _context.DbLogs.Add(log);
            _context.SaveChanges();
        }
        public async Task <ActionResult> Create(Item item, int CategoryId)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            item.User = currentUser;
            _db.Items.Add(item);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #16
0
        public IActionResult CompleteTask(int Id, bool isComplete)
        {
            TaskList t = _db.TaskList.Find(Id);

            t.Complete = isComplete;

            _db.TaskList.Update(t);
            _db.SaveChanges();
            return(RedirectToAction("Welcome"));
        }
        public IActionResult Add(ToDoItem toDoItem)
        {
            if (ModelState.IsValid)
            {
                _context.ToDoItems.Add((toDoItem));
                _context.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Beispiel #18
0
 public static void SetDefaultProjects()
 {
     Db.ProjectsDto.Add(new Project {
         ProjectName = "Home"
     });
     Db.ProjectsDto.Add(new Project {
         ProjectName = "Work"
     });
     Db.SaveChanges();
 }
        public void Create(MapId item)
        {
            if (ReferenceEquals(item, null))
            {
                throw new ArgumentNullException();
            }

            _context.MapIds.Add(item);
            _context.SaveChanges();
        }
Beispiel #20
0
        public bool CheckCredentials(string UserId, string Password)
        {
            bool isAuthorised = false;

            try
            {
                using (context)
                {
                    var query = from u in context.UserTable
                                where u.Id == UserId && u.Psw == Password
                                select u;
                    var user = query.ToList();
                    if (user.Count > 0)
                    {
                        isAuthorised = true;
                    }
                    context.SaveChanges();
                }
                return(isAuthorised);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Beispiel #21
0
        public ActionResult Create([Bind(Include = "ListID,Title,Date")] List list)
        {
            if (ModelState.IsValid)
            {
                db.Lists.Add(list);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(list));
        }
Beispiel #22
0
        public ActionResult Create(string Name)
        {
            Category newCategory = new Category()
            {
                Name = Name
            };

            _db.Categories.Add(newCategory);
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #23
0
        public ActionResult Create([Bind(Include = "Id,Name,Description")] Tasks tasks)
        {
            if (ModelState.IsValid)
            {
                db.Tasks.Add(tasks);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tasks));
        }
        public void Create(Item item)
        {
            var s = _context.Items;

            if (ReferenceEquals(item, null))
            {
                throw new ArgumentNullException();
            }

            _context.Items.Add(item);
            _context.SaveChanges();
        }
Beispiel #25
0
 public ActionResult AddCategory(Item item, int CategoryId)
 {
     if (CategoryId != 0)
     {
         _db.CategoryItem.Add(new CategoryItem()
         {
             CategoryId = CategoryId, ItemId = item.ItemId
         });
     }
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Beispiel #26
0
 public ActionResult Edit(Item item, int CategoryId)
 {
     if (CategoryId != 0)
     {
         _db.CategoryItem.Add(new CategoryItem()
         {
             CategoryId = CategoryId, ItemId = item.ItemId
         });
     }
     _db.Entry(item).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
        public IActionResult Create(Tarefa tarefa)
        {
            // verificando se o model está válido
            if (!ModelState.IsValid)
            {
                return(View(tarefa));
            }

            // inserindo o registro
            _context.Add(tarefa);
            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Create(Category category)
        {
            var userId      = this.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var currentUser = await _userManager.FindByIdAsync(userId);

            category.User = currentUser;
            _db.Categories.Add(category);
            _db.ApplicationUserCategory.Add(new ApplicationUserCategory()
            {
                ApplicationUser = currentUser, CategoryId = category.CategoryId
            });
            _db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #29
0
 public ActionResult Create([Bind(Include = "itemNumber,itemText,DateAdded,Completed")] ToDoListItem toDoListItem)
 {
     //Checks if the model state is valid
     if (ModelState.IsValid)
     {   //adds a ToDoListItem to the database context
         db.ToDoListItems.Add(toDoListItem);
         //Saves the changes to the database context
         db.SaveChanges();
         //Goes back to the original view for this controller
         return(RedirectToAction("Index"));
     }
     //If the model state isn't valid, it goes back to the Create view with the item back in
     return(View(toDoListItem));
 }
Beispiel #30
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="repassword"></param>
        /// <returns></returns>
        public int Register(string userName, string password, string repassword)
        {
            var userList = _database.Users;
            var judge    = false;

            if (userName == null || password == null || repassword == null)
            {
                return(-2);
            }
            else
            {
                foreach (var item in userList)
                {
                    if (item.UserName != userName)
                    {
                        judge = true;
                    }
                    else
                    {
                        judge = false;
                    }
                }
                if (judge)
                {
                    if (password.Equals(repassword))
                    {
                        var user = new Users()
                        {
                            EMail    = "zvvxcv",
                            UserName = userName,
                            Password = password,
                            Birthday = DateTime.Now,
                            Sex      = "男"
                        };
                        _database.Users.Add(user);
                        _database.SaveChanges();
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                }
                else
                {
                    return(-1);
                }
            }
        }