コード例 #1
0
 //Delete category
 public void DeleteCat(int Id)
 {
     using (WalkAboutDb dc = new WalkAboutDb())
     {
         dc.Categories.Remove(dc.Categories.Single<Category>(c => c.CatId == Id));
         //or use a regular Linq query
     }
 }
コード例 #2
0
 //readonly Models.WalkAboutDb dc = new Models.WalkAboutDb("WalkAboutDb");
 public IEnumerable<User> GetAll()
 {
     using (WalkAboutDb dc = new WalkAboutDb())
     {
         var AllUsers = (from a in dc.Users
                         select a).ToList();
         return AllUsers;
     }
 }
コード例 #3
0
        //get category by ID
        public Category GetByID(int Id)
        {
            using (WalkAboutDb dc = new WalkAboutDb())
            {
                var CatById = (from c in dc.Categories
                               where c.CatId == Id
                               select c);

                return CatById.First();
            }
        }
コード例 #4
0
        //get all categories
        public IEnumerable<Category> GetAllCat()
        {
            using (WalkAboutDb dc = new WalkAboutDb())
            {
                var allCategory = (from a in dc.Categories
                                   select a).ToList();

                return allCategory;

            }
        }
コード例 #5
0
        //PUT
        public void UpdateUser(User user)
        {
            using (WalkAboutDb dc = new WalkAboutDb())
            {
                var CurUser = (from a in dc.Users
                               where a.UsrId == user.UsrId
                               select a).FirstOrDefault();
                CurUser.Fname = user.Fname;
                CurUser.Lname = user.Lname;
                CurUser.CurrentCity = user.CurrentCity;
                dc.SaveChanges();

            }
        }
コード例 #6
0
        // GET /api/user/5
        public User GetById(string Id)
        {
            using (WalkAboutDb dc = new WalkAboutDb())
            {
                var UserByID = (from a in dc.Users
                                where a.UsrId == Id
                                select a);

                return UserByID.First();

                //or
                //return dc.Users.FirstOrDefault(u => u.UsrId == Id);
            }
        }
コード例 #7
0
        // POST
        public void AddUser(User user)
        {
            using (WalkAboutDb dc = new WalkAboutDb())
            {
                User usr = new User {
                 UsrId = user.UsrId ,
                 Fname = user.Fname ,
                 Lname = user.Lname ,
                 CurrentCity = user.CurrentCity

                };

                dc.Users.Add(usr);
                dc.SaveChanges();

            }
        }
コード例 #8
0
        //Post Category
        public void AddCategory(Category category)
        {
            using (WalkAboutDb dc = new WalkAboutDb())
            {
                Category cat = new Category
                {

                    CatId = category.CatId,
                    CategoryName = category.CategoryName,
                    IconNameLocal = category.IconNameLocal

                };

                dc.Categories.Add(cat);
                dc.SaveChanges();
            }
        }
コード例 #9
0
        //handles updates
        //Put Category
        public Category UpdateCategory(Category category)
        {
            using (WalkAboutDb dc = new WalkAboutDb())
            {

               //get the current category

                var CurCat = (from a in dc.Categories
                              where a.CatId == category.CatId
                              select a).FirstOrDefault ();

                //perform update
                CurCat.CategoryName = category.CategoryName;
                CurCat.IconNameLocal = category.IconNameLocal;
                //persist to dbase
                dc.SaveChanges();

                return CurCat;
            }
        }