예제 #1
0
 public void EditUserSubCategories(UserWithSubCategories applicationUser)
 {
     foreach (SubCategory subCategory in applicationUser.SubCategories)
     {
         _db.UserSubCategories.Add(new UserSubCategory {
             ApplicationUserId = applicationUser.Id, SubCategoryId = subCategory.Id
         });
     }
     _db.SaveChanges();
 }
예제 #2
0
 public IActionResult Post([FromBody] UserWithSubCategories applicationUser)
 {
     if (applicationUser == null)
     {
         return(BadRequest());
     }
     else if (applicationUser.Id == null)
     {
         return(BadRequest());
     }
     else
     {
         _uscService.EditUserSubCategories(applicationUser);
         return(Ok());
     }
 }
예제 #3
0
        public UserWithSubCategories GetUserSubCategories(string id)
        {
            UserWithSubCategories appUser = (from au in _repo.Query <ApplicationUser>()
                                             where au.Id == id
                                             select new UserWithSubCategories
            {
                Id = au.Id,
                FirstName = au.FirstName,
                LastName = au.LastName,
                SubCategories = (from usc in _repo.Query <UserSubCategory>()
                                 where usc.ApplicationUserId == au.Id
                                 select usc.SubCategory).ToList()
            }).FirstOrDefault();

            return(appUser);
        }