public async Task <ExperienceCategory> UpdateExperienceCategoryAsync(ExperienceCategory category, string userId) { var existing = await GetExperienceCategoryAsync(category.Id, userId);//this is more for cheking that category is for this user if (existing != null) { existing.Name = category.Name; _context.Update(existing); await _context.SaveChangesAsync(); } return(existing); }
public async Task<IActionResult> UpdateExperienceCategory([FromBody] ExperienceCategory category) { try { var userId = User.Identity.Name; category = await _organizerService.UpdateExperienceCategoryAsync(category, userId); return Ok(category); } catch (Exception ex) { return BadRequest(ex.Message); } }
public async Task <ExperienceCategory> AddExperienceCategoryAsync(ExperienceCategory experienceCategory, string userId) { var group = await _context .ExperienceCategoryGroups .FirstOrDefaultAsync(acg => acg.ApplicationUserId == userId && acg.Id == experienceCategory.ExperienceCategoryGroupId); if (group != null) { _context.Add(experienceCategory); await _context.SaveChangesAsync(); return(experienceCategory); } throw new Exception("Could not add a category");//this should never happen }