コード例 #1
0
ファイル: DBHandler.cs プロジェクト: hjrsantos/MyMVC
        //additional features for knockout demo
        public static List<TodoItem> getAllTodoItems()
        {
            using (var db = new OrganizerDBContext()) {

                return db.TodoItems.ToList();
            }
        }
コード例 #2
0
ファイル: DBHandler.cs プロジェクト: hjrsantos/MyMVC
        public static IEnumerable<Category> getAllCategories()
        {
            List<Category> listCategories = new List<Category>();
            using(var db = new OrganizerDBContext()){

                listCategories = db.Categories.ToList();
            }
            return listCategories;
        }
コード例 #3
0
ファイル: DBHandler.cs プロジェクト: hjrsantos/MyMVC
        public static void deleteTodoItemById(int id)
        {
            TodoItem todoItem = getAppUserByUserName(HttpContext.Current.User.Identity.Name).ThingsTodo.FirstOrDefault(p => p.Id == id);

            using(var db = new OrganizerDBContext()){

                db.Entry(todoItem).State = System.Data.EntityState.Deleted;
                db.SaveChanges();

            }
        }
コード例 #4
0
ファイル: DBHandler.cs プロジェクト: hjrsantos/MyMVC
 public static AppUser getAppUserByUserName(string sUserName)
 {
     AppUser oAppUser = null;
     using(var db = new OrganizerDBContext()){
         oAppUser =
             db.
             AppUsers.
             Include("ThingsTodo").
             Where(p => p.UserName == sUserName).
             FirstOrDefault();
     }
     return oAppUser;
 }
コード例 #5
0
ファイル: DBHandler.cs プロジェクト: hjrsantos/MyMVC
        public static void EditTodoItem(TodoItemDTO todoItemDTO, int todoItemId)
        {
            TodoItem todoItem =
                getAppUserByUserName(HttpContext.Current.User.Identity.Name).
                ThingsTodo.
                FirstOrDefault(p=>p.Id == todoItemId);

            if (todoItem == null)
                throw new Exception("Access denied");

            todoItem.CategoryId = todoItemDTO.SelectedCategoryId;
            todoItem.Completed = todoItemDTO.SelectedCompletedId == 0 ? false : true;
            todoItem.Title = todoItemDTO.Title;

            using (var db = new OrganizerDBContext())
            {
                db.TodoItems.Attach(todoItem);
                db.Entry(todoItem).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
        }
コード例 #6
0
ファイル: DBHandler.cs プロジェクト: hjrsantos/MyMVC
        public static bool registerUser(RegisterDTO oDTO)
        {
            if(!isUserNameUnique(oDTO.UserName))
                return false;

            using (var db = new OrganizerDBContext())
            {

                AppUser oAppUser = new AppUser();
                oAppUser.UserName = oDTO.UserName;
                oAppUser.Password = PasswordHash.CreateHash(oDTO.Password);

                db.AppUsers.Add(oAppUser);
                db.Entry(oAppUser).State = System.Data.EntityState.Added;
                db.SaveChanges();
            }
            return true;
        }
コード例 #7
0
ファイル: DBHandler.cs プロジェクト: hjrsantos/MyMVC
 private static bool isUserNameUnique(string userName)
 {
     AppUser appUser;
     using (var db = new OrganizerDBContext()) {
         appUser = db.AppUsers.SingleOrDefault(p => p.UserName == userName);
     }
     return appUser == null;
 }
コード例 #8
0
ファイル: DBHandler.cs プロジェクト: hjrsantos/MyMVC
        public static void updateTodoItem(TodoItem oTodoItem)
        {
            using (var db = new OrganizerDBContext())
            {

                db.TodoItems.Attach(oTodoItem);
                db.Entry(oTodoItem).State = System.Data.EntityState.Modified;
                db.SaveChanges();

            }
        }
コード例 #9
0
ファイル: DBHandler.cs プロジェクト: hjrsantos/MyMVC
        public static void saveTodoItem(TodoItemDTO todoItemDTO)
        {
            using(var db = new OrganizerDBContext()){

                AppUser appUser =
                    db.
                    AppUsers.
                    Include("ThingsTodo").
                    Single(p => p.UserName == HttpContext.Current.User.Identity.Name);
                appUser.ThingsTodo.Add(
                    new TodoItem { CategoryId = todoItemDTO.SelectedCategoryId, Title = todoItemDTO.Title, Completed = false }
                );

                db.AppUsers.Attach(appUser);
                db.Entry(appUser).State = System.Data.EntityState.Modified;
                db.SaveChanges();
            }
        }
コード例 #10
0
ファイル: DBHandler.cs プロジェクト: hjrsantos/MyMVC
        public static void saveNewTodoItem(TodoItem oTodoItem)
        {
            using(var db = new OrganizerDBContext()){

                db.TodoItems.Add(oTodoItem);
                db.Entry(oTodoItem).State = System.Data.EntityState.Added;
                db.SaveChanges();

            }
        }