public async Task <GenericResponse <ICollection <TDto> > > BulkInsert(GenericRequest <ICollection <TDto> > request) { var response = new GenericResponse <ICollection <TDto> >(); var totalIndex = (int)Math.Ceiling((double)request.Data.Count / BulkInsertDataSize); for (int index = 0; index < totalIndex; index++) { var dtoCollection = request.Data.Skip(index * BulkInsertDataSize).Take(BulkInsertDataSize).ToList(); response.Data = await this._repository.BulkInsert(dtoCollection); } response.AddInfoMessage(GeneralResource.Info_Saved); return(response); }
public virtual async Task <GenericResponse <TDto> > DeleteAsync(GenericRequest <TDtoType> request) { var response = new GenericResponse <TDto>(); var dto = await _repository.DeleteAsync(request.Data); if (dto == null) { response.AddErrorMessage(GeneralResource.Item_Delete_NotFound); return(response); } response.Data = dto; response.AddInfoMessage(GeneralResource.Info_Deleted); return(response); }
public async Task <GenericResponse <object> > RemoveRole(AddRemoveRoleDto removeRoleDto) { try { var user = await _userRepository.FindById(removeRoleDto.UserId); if (user is null) { return(new GenericResponse <object>(new object(), false).AddErrorMessage("User doesn't exists")); } var role = await _roleRepository.FindById(removeRoleDto.RoleId); var removed = user.RemoveRole(role); await _userRepository.UnitOfWork.Commit(); var response = new GenericResponse <object>(new object(), removed); if (removed) { response.AddInfoMessage("Successfully removed"); } else { response.AddErrorMessage("Cannot remove - check if role exists"); } return(response); } catch (Exception) { await _userRepository.UnitOfWork.Rollback(); throw; } }