// getting userid from header directly public async Task <ServiceResponse <List <GetCharecterDto> > > addNewCharecter(AddCharecterDto objOfClass) { ServiceResponse <List <GetCharecterDto> > serviceResponse = new ServiceResponse <List <GetCharecterDto> >(); Charecter chars = _mapper.Map <Charecter>(objOfClass); // chars.Id = knights.Max(ob => ob.Id) + 1; // getting max id and incrementing it using LINQ // knights.Add(chars); chars.Users = await _contect.Users.FirstOrDefaultAsync(x => x.Id == GetUserID()); await _contect.charecters.AddAsync(chars); await _contect.SaveChangesAsync(); serviceResponse.data = (_contect.charecters.Where(u => u.Users.Id == GetUserID()).Select(ob => _mapper.Map <GetCharecterDto>(ob))).ToList(); // this select all data and convert to dto object and make it List // // this where for getting records based on reference key and Select for mapping records to list return(serviceResponse); }
public async Task <IActionResult> AddCharecter(AddCharecterDto chars) { return(Ok(await _charecterService.addNewCharecter(chars))); }