public async Task <IActionResult> AddRoleDetails([FromBody] AppUserRoleDetail model) { if (ModelState.IsValid) { try { logger.LogInformation("Adding Role Details in Repository"); var addedRoleDetails = await roleRepo.AddUserRoleDetails(model); if (addedRoleDetails != null) { return(Ok(addedRoleDetails)); } else { return(NotFound()); } } catch (Exception excp) { logger.LogError("Error Adding Role Details in Repository " + excp.Message); return(BadRequest(excp)); } } return(BadRequest()); }
public async Task <AppUserRoleDetail> AddUserRoleDetails(AppUserRoleDetail userRoleDetail) { if (userRoleDetail != null) { // We dont have referential integrity so we must verify dependent legit ids var appRoleUserId = db.AppUserRole.FindAsync(userRoleDetail.AppUserRoleId); var appUITemplate = db.AppUitemplate.FindAsync(userRoleDetail.AppUitemplateId); if (appRoleUserId != null && appUITemplate != null) { userRoleDetail.AppUserRoleDetailId = Guid.NewGuid(); userRoleDetail.CreatedDate = DateTime.Now; await db.AppUserRoleDetail.AddAsync(userRoleDetail); await db.SaveChangesAsync(); } } return(userRoleDetail); }