public async Task <IActionResult> JobCategory(UserJobCategoryViewModal category) { category.UserJobCatList.ForEach(val => { var user = _profileDbContext.UserJobCategory.ToList().Find(v => v.JobCategoryId == val.CatId); if (val.IsUserCategory) { if (user == null) { _profileDbContext.UserJobCategory.Add(new Models.Profile.UserJobCategory { UserId = category.UserId, JobCategoryId = val.CatId }); } } else { if (user != null) { var toDelete = _profileDbContext.UserJobCategory.Where(v => v.JobCategoryId == val.CatId).FirstOrDefault(); if (toDelete != null) { _profileDbContext.UserJobCategory.Remove(toDelete); } } } }); _profileDbContext.SaveChanges(); return(await Task.Run(() => View(category))); }
public async Task <IActionResult> JobCategory() { return(await Task.Run(() => { var userJobCatJoin = from jobCat in _profileDbContext.JobCategory.Where(jc => jc.CategoryStatus == 1) from userJobCat in _profileDbContext.UserJobCategory.Where(ujc => ujc.JobCategoryId == jobCat.Id && ujc.UserId == UserId) .DefaultIfEmpty() select new { jobCat, userJobCat }; var userCatList = new UserJobCategoryViewModal(); userCatList.UserId = UserId; userJobCatJoin.ForEachAsync(val => { userCatList.UserJobCatList.Add( new UserJobCat { CatId = val.jobCat.Id, CatName = val.jobCat.CategoryName, DispName = val.jobCat.DisplayName, UserJobCatId = val.userJobCat != null ? val.userJobCat.Id : new Guid(), IsUserCategory = val.userJobCat != null }); }); return View(userCatList); //return await Task.Run(() => View(userCatList)); })); }